]> Creatis software - clitk.git/blob - docWiki.sh
Add doc tool for th wiki
[clitk.git] / docWiki.sh
1 #Write all help of syd tools in a file sydTool.md
2 #Execute it in src folder but the tools have to be into ../bin/bin (or change it)
3 #Results are in src folder
4
5 #!/bin/bash
6 set -ev
7 currentFolder=$PWD
8 #Copy all help into a temporary file
9 tempFile=tempDoc.txt
10 cd ./vv_bin/bin
11 clitkTools=`ls clitk*`
12 echo "This page contains additional information on how to use clitk tools:" > $tempFile
13 echo "" >> $tempFile
14 for tool in $clitkTools
15 do
16   echo "==== " $tool " ====" >> $tempFile
17   $tool -h >> $tempFile
18   echo "" >> $tempFile
19   echo "" >> $tempFile
20   echo "" >> $tempFile
21   echo "" >> $tempFile
22 done
23
24 #Write the .md file
25 docFile="$currentFolder/clitkTool.txt"
26 rm $docFile
27 helpLine=false  #Boolean to know if we are reading the command lines starting with '-h, --help' and finishing with '##' or just the help
28 echoLine=""
29 writeLine=false;
30 while IFS='' read -r line || [[ -n "$line" ]]; do #read all lines
31     copyLine=$line;
32     line=`echo "$line" | sed -e 's/^[ \t]*//'`; # prevent whitespace at the begining of the line
33     if [[ $line == *"-h, --help"* ]]; then
34       helpLine=true;
35     fi
36     if [[ $line == *"===="* ]]; then
37       if $writeLine; then
38         echo "$echoLine||" >> $docFile;
39       fi
40       echoLine="";
41       echo "" >> $docFile;
42       echo "" >> $docFile;
43       echo "" >> $tempFile
44       echo "" >> $tempFile
45       writeLine=false;
46       helpLine=false;
47     fi
48
49     if $helpLine; then
50       if [[ $line == "" ]]; then
51         continue;
52       fi
53       #Create the string according to the different case of ggo
54       #Start with -h
55       #Start with --help
56       #Start with comment
57       #Start with title
58       if [[ $line == "-"[a-zA-Z]* ]]; then
59         if $writeLine; then
60           echoLine="$echoLine||";
61           echo "$echoLine" >> $docFile;
62         fi
63         writeLine=true;
64         echoLine="||";
65         tempString=`echo "$line" | cut -c1-2`; # eg take the -h
66         echoLine="$echoLine$tempString";
67         line=`echo "$line" | cut -d' ' -f2-`; # remove -h, (first word)
68         line=`echo "$line" | sed -e 's/^[ \t]*//'`; # prevent whitespace at the begining of the line
69         echoLine="$echoLine||";
70         tempString=`echo "$line" | cut -f 1 -d " "`; # eg take the --help (first word)
71         echoLine="$echoLine$tempString";
72         line=`echo "$line" | cut -d' ' -f2-`; # remove --help (first word)
73         line=`echo "$line" | sed -e 's/^[ \t]*//'`; # prevent whitespace at the begining of the line
74         echoLine="$echoLine||$line";
75       elif [[ $line == "--"* ]]; then
76         if $writeLine; then
77           echoLine="$echoLine||";
78           echo "$echoLine" >> $docFile;
79         fi
80         writeLine=true;
81         echoLine="|| ||";
82         tempString=`echo "$line" | cut -f 1 -d " "`; # eg take the --help (first word)
83         echoLine="$echoLine$tempString";
84         line=`echo "$line" | cut -d' ' -f2-`; # remove --help (first word)
85         line=`echo "$line" | sed -e 's/^[ \t]*//'`; # prevent whitespace at the begining of the line
86         echoLine="$echoLine||$line";
87       elif [[ $copyLine == " "* ]]; then
88         echoLine="$echoLine$line";
89       else
90         if $writeLine; then
91           echoLine="$echoLine||";
92           echo "$echoLine" >> $docFile;
93         fi
94         echoLine="||||||<style=\"&quot; &amp; quot;text-align:center&amp; quot; &quot;\">$line||";
95         echo "$echoLine" >> $docFile;
96         echoLine="";
97         writeLine=false;
98       fi
99     else
100       if [[ `echo "$line" | cut -c1-1` = "-" ]]; then
101         echo "  " >> $docFile;
102         echo "\\$line" >> $docFile;
103       else
104         echo "$line" >> $docFile;
105       fi
106     fi
107 done < "$tempFile"
108 echo "$echoLine||" >> $docFile
109 rm $tempFile
110 cd $currentFolder