11#! /usr/bin/bash
22
33SRC=
4- ASMB_DIR=common # assembly destination folder
5- MOD_DIR=modules
4+ MOD_DIR=common/hammer-reference/
65MOD_TYPE=" :_mod-docs-content-type: REFERENCE"
7- ASMB_FILENAME=assembly_hammer-reference.adoc
6+ ROLE_ABSTRACT=' [role="_abstract"]'
7+ ASMB_FILENAME=doc-Hammer_Reference/master.adoc
88NOOP= # dry run
99DEBUG=
1010
1111print_help () {
1212 echo -e " Generate AsciiDoc reference from a Hammer full-help MarkDown file"
13- echo -e " Generates one assembly and one module per hammer command ."
13+ echo -e " Generates $ASMB_FILENAME and one module per hammer subsubcommand (3 levels) ."
1414 echo
1515 echo -e " Usage:"
1616 echo -e " $0 [OPTIONS ...] SOURCE_FILE"
@@ -19,9 +19,8 @@ print_help() {
1919 echo
2020 echo -e " Options:"
2121 echo -e " --target-dir, -T DIR"
22- echo -e " Path to a folder where the reference assembly"
23- echo -e " will be placed. Default: $ASMB_DIR "
24- echo -e " Modules will be placed in $ASMB_DIR /$MOD_DIR /"
22+ echo -e " Path to a folder where the reference modules"
23+ echo -e " will be placed. Default: $MOD_DIR "
2524 echo -e " --help, -h Print help and exit"
2625 echo -e " --noop Dry run (don't do anything, only preview output)"
2726 echo -e " --debug, -d Debug mode (verbose output and keep tmp file)"
@@ -37,10 +36,10 @@ bye() {
3736
3837# Process user arguments
3938if [ $# -eq 0 ]; then print_help; exit 1; fi
40- while [ $# -gt 1 ]; do
39+ while [ $# -gt 0 ]; do
4140 case " $1 " in
4241 --target-dir|-T)
43- ASMB_DIR =" $2 "
42+ MOD_DIR =" $2 "
4443 shift 2
4544 ;;
4645 --noop)
@@ -64,32 +63,37 @@ while [ $# -gt 1 ]; do
6463 print_help
6564 exit 0
6665 ;;
67- * )
66+ - * )
6867 bye " E: Invalid option: $1 "
6968 ;;
69+ * )
70+ break
7071 esac
7172done
7273SRC=$1
7374
74- # Define internal variables
75- if [ -n " $ASMB_DIR " ]; then
76- mod_path=$ASMB_DIR /$MOD_DIR # module destination folder
77- asmb_file=$ASMB_DIR /$ASMB_FILENAME
78- else
79- mod_path=$MOD_DIR
80- asmb_file=$ASMB_FILENAME
75+ # Exit if source file doesn't exist
76+ if [ ! -f " $SRC " ]; then
77+ bye " E: Source file not found: $SRC "
8178fi
79+
80+ # Define internal variables
81+ mod_path=${MOD_DIR%/ }
82+ asmb_file=$ASMB_FILENAME
8283details_tmp=" $mod_path /tmp_hammer-option-details"
83- echo -e > $details_tmp # reset
8484
85- details_file=" $mod_path /ref_hammer-option-details .adoc"
86- details_header=' [id="hammer-option-details "]\n= Option details \n\nHammer options accept the following option types and values: '
85+ details_file=" $mod_path /ref_data-representation-in-hammer-options .adoc"
86+ details_header=" $MOD_TYPE \n\n [id=" data-representation-in-hammer-options " ]\n= Data representation in Hammer options \n\n $ROLE_ABSTRACT \ nHammer options accept the following types and values. "
8787
88- asmb_header=' :_mod-docs-content-type: ASSEMBLY \n\n // DO NOT EDIT MANUALLY\n// Use the generate-hammer-reference.sh script to update\n\ninclude::modules/con_hammer-reference .adoc[]\n\n '
89- asmb_footer=' include::modules/ref_hammer-option-details .adoc[leveloffset=+1 ]\n'
88+ asmb_header=" include::common/attributes.adoc[]\ninclude::common/header.adoc[]\n:context: hammer-reference\n:hammer-reference:\n\n= {HammerRefDocTitle} \n\nifdef::satellite[]\ninclude::common/modules/proc_providing-feedback-on-red-hat-documentation.adoc[leveloffset=+1]\nendif::[]\n\n // DO NOT EDIT MANUALLY! \n// Use the generate-hammer-reference.sh script to update\n\ninclude::$mod_path /ref_data-representation-in-hammer-options .adoc[leveloffset=+1 ]\n"
89+ asmb_footer=' ifndef::orcharhino,satellite[]\ninclude::common/ribbons .adoc[]\nendif::[ ]\n'
9090
91- # Create folders
92- { [ -n " $NOOP " ] || mkdir -p $mod_path ; } && echo -e " Created folders: " $mod_path
91+ # Exit if module path doesn't exist
92+ if [ -d " $mod_path " ]; then
93+ echo " I: Module path exists: $mod_path "
94+ else
95+ bye " E: Module path not found: $mod_path "
96+ fi
9397
9498# Output headers
9599if [ -z " $NOOP " ]; then
@@ -98,8 +102,7 @@ if [ -z "$NOOP" ]; then
98102fi
99103if [ -z " $ASSEMBLY_ONLY " ]; then
100104 echo -e " $details_header " > $details_file && \
101- { [ -n " $DEBUG " ] && echo -e " I: Option details header written" ; } || \
102- echo -e " W: Something went wrong writing option details header"
105+ [ -n " $DEBUG " ] && echo -e " I: Data representation header written"
103106fi
104107
105108# Read lines from the source file
@@ -115,31 +118,31 @@ cat "$SRC" | while read line ; do
115118 ' - [' * ) # Skip MD TOC
116119 continue
117120 ;;
118- " # hammer" ) # top-command
121+ " # hammer" ) # program
119122 echo -e " I: [cmd-1]: $line "
120123 id_core=hammer
121124 mod_file=" $mod_path /ref_$id_core .adoc"
122125 id=' [id="hammer"]'
123126 heading=' = hammer'
124127 [ -n " $NOOP " ] || [ -n " $ASSEMBLY_ONLY " ] || \
125- echo -e " $MOD_TYPE \n\n$id \n$heading " > $mod_file
128+ echo -e -n " $MOD_TYPE \n\n$id \n$heading \n\n $ROLE_ABSTRACT " > $mod_file
126129 { [ -z " $NOOP " ] || [ -n " $ASSEMBLY_ONLY " ] ; } && \
127- echo -e " include::modules /ref_hammer.adoc[leveloffset=+1]\n" >> $asmb_file
130+ echo -e " include::$mod_path /ref_hammer.adoc[leveloffset=+1]\n" >> $asmb_file
128131 begin_section=yes
129132 skip_section=
130133 continue
131134 ;;
132135 " ## hammer" * ) # command
133136 echo -e " I: [cmd-2]: $line "
134137 id_core=` echo -e $line | sed ' s/^## //' | sed ' s/ /-/g' `
135- filename=ref_$id_core .adoc
138+ filename=ref_${ id_core} .adoc
136139 mod_file=" $mod_path /$filename "
137- id=[id= \" $id_core \" ]
140+ id=[id= \" ${ id_core} \" ]
138141 heading=` echo -e $line | sed ' s/^## hammer/=/' `
139142 [ -n " $NOOP " ] || [ -n " $ASSEMBLY_ONLY " ] || \
140- echo -e " $MOD_TYPE \n\n$id \n$heading " > $mod_file
143+ echo -e -n " $MOD_TYPE \n\n$id \n$heading \n\n $ROLE_ABSTRACT " > $mod_file
141144 { [ -z " $NOOP " ] || [ -n " $ASSEMBLY_ONLY " ] ; } && \
142- echo -e " include::modules /$filename [leveloffset=+1]\n" >> $asmb_file
145+ echo -e " include::$mod_path /$filename [leveloffset=+1]\n" >> $asmb_file
143146 begin_section=yes
144147 skip_section=
145148 options=
@@ -152,10 +155,14 @@ cat "$SRC" | while read line ; do
152155 " ### hammer" * ) # subcommand
153156 [ -n " $DEBUG " ] && echo -e " I: [cmd-3]: $line "
154157 id_core=` echo -e $line | sed ' s/^### //' | sed ' s/ /-/g' `
155- id=[id= \" $id_core \" ]
156- heading=` echo -e $line | sed ' s/^### hammer/==/' `
158+ id=[id= \" ${id_core} \" ]
159+ filename=ref_${id_core} .adoc
160+ mod_file=" $mod_path /$filename "
161+ heading=` echo -e $line | sed ' s/^### hammer/=/' `
157162 [ -n " $NOOP " ] || [ -n " $ASSEMBLY_ONLY " ] || \
158- echo -e " $MOD_TYPE \n\n$id \n$heading " >> $mod_file
163+ echo -e -n " $MOD_TYPE \n\n$id \n$heading \n\n$ROLE_ABSTRACT " >> $mod_file
164+ { [ -z " $NOOP " ] || [ -n " $ASSEMBLY_ONLY " ] ; } && \
165+ echo -e " include::$mod_path /$filename [leveloffset=+2]\n" >> $asmb_file
159166 begin_section=yes
160167 skip_section=
161168 options=
@@ -168,10 +175,14 @@ cat "$SRC" | while read line ; do
168175 " #### hammer" * ) # subsubcommand
169176 [ -n " $DEBUG " ] && echo -e " I: [cmd-4]: $line "
170177 id_core=` echo -e $line | sed ' s/^#### //' | sed ' s/ /-/g' `
171- id=[id= \" $id_core \" ]
172- heading=` echo -e $line | sed ' s/^#### hammer/===/' `
178+ id=[id= \" ${id_core} \" ]
179+ filename=ref_${id_core} .adoc
180+ mod_file=" $mod_path /$filename "
181+ heading=` echo -e $line | sed ' s/^#### hammer/=/' `
173182 [ -n " $NOOP " ] || [ -n " $ASSEMBLY_ONLY " ] || \
174- echo -e " $MOD_TYPE \n\n$id \n$heading " >> $mod_file
183+ echo -e -n " $MOD_TYPE \n\n$id \n$heading \n\n$ROLE_ABSTRACT " >> $mod_file
184+ { [ -z " $NOOP " ] || [ -n " $ASSEMBLY_ONLY " ] ; } && \
185+ echo -e " include::$mod_path /$filename [leveloffset=+3]\n" >> $asmb_file
175186 begin_section=yes
176187 skip_section=
177188 options=
@@ -184,10 +195,10 @@ cat "$SRC" | while read line ; do
184195 " ##### hammer" * ) # subsubsubcommand
185196 [ -n " $DEBUG " ] && echo -e " I: [cmd-5]: $line "
186197 id_core=` echo -e $line | sed ' s/^##### //' | sed ' s/ /-/g' `
187- id=[id= \" $id_core \" ]
188- heading=` echo -e $line | sed ' s/^##### hammer/==== /' `
198+ id=[id= \" ${ id_core} \" ]
199+ heading=` echo -e $line | sed ' s/^##### hammer/==/' `
189200 [ -n " $NOOP " ] || [ -n " $ASSEMBLY_ONLY " ] || \
190- echo -e " $MOD_TYPE \n\n $ id \n$heading " >> $mod_file
201+ echo -e " $id \n$heading " >> $mod_file
191202 begin_section=yes
192203 skip_section=
193204 options=
@@ -200,7 +211,7 @@ cat "$SRC" | while read line ; do
200211 " Usage:" )
201212 [ -n " $DEBUG " ] && echo -e " I: [Usage]ID: $id_core "
202213 [ -n " $NOOP " ] || [ -n " $ASSEMBLY_ONLY " ] || \
203- echo -e " . Usage" >> $mod_file
214+ echo -e " * Usage*\n " >> $mod_file
204215 skip_section=
205216 continue
206217 ;;
@@ -223,15 +234,15 @@ cat "$SRC" | while read line ; do
223234 " Options:" )
224235 [ -n " $DEBUG " ] && echo -e " I: [Options]ID: $id_core "
225236 [ -n " $NOOP " ] || [ -n " $ASSEMBLY_ONLY " ] || \
226- echo -e " . Options" >> $mod_file
237+ echo -e " * Options*\n " >> $mod_file
227238 options=yes
228239 skip_section=
229240 continue
230241 ;;
231242 * " Predefined field sets" * )
232243 [ -n " $DEBUG " ] && echo -e " I: [Predefined field sets]ID: $id_core "
233244 [ -n " $NOOP " ] || [ -n " $ASSEMBLY_ONLY " ] || \
234- echo -e " . Predefined field sets" >> $mod_file
245+ echo -e " * Predefined field sets*\n " >> $mod_file
235246 field_sets=yes
236247 table_delim=0
237248 skip_section=
@@ -249,7 +260,7 @@ cat "$SRC" | while read line ; do
249260 " Provider specific options:" )
250261 [ -n " $DEBUG " ] && echo -e " I: [Provider specific options]ID: $id_core "
251262 [ -n " $NOOP " ] || [ -n " $ASSEMBLY_ONLY " ] || \
252- echo -e " . Provider specific options\n" >> $mod_file
263+ echo -e " * Provider- specific options* \n" >> $mod_file
253264 provider_specific=yes
254265 skip_section=
255266 options=
@@ -260,7 +271,7 @@ cat "$SRC" | while read line ; do
260271 * Search* fields* )
261272 [ -n " $DEBUG " ] && echo -e " I: [Search / Order fields]ID: $id_core "
262273 [ -n " $NOOP " ] || [ -n " $ASSEMBLY_ONLY " ] || \
263- echo -e " . Search / Order fields" >> $mod_file
274+ echo -e " * Search and order fields*\n " >> $mod_file
264275 search_fields=yes
265276 skip_section=
266277 options=
@@ -328,7 +339,7 @@ cat "$SRC" | while read line ; do
328339 fixed_line=` echo -e " $fixed_line " | sed -E ' s/..1m|..0m/\*/g' ` # bold
329340 if echo -e " ${line} " | grep -Eq ' ^-{1,2}[a-z\[]' - ; then # option line
330341 fixed_line=` echo -e " $fixed_line " | sed -E ' s/^(-[a-z])/\`\1\`/' | sed -E ' s/( )(-[a-z])/\1\`\2\`/g' `
331- fixed_line=` echo -e " $fixed_line " | sed -E ' s/(--\S+\s[A-Z\_]{3,})/\`\1\`/' | sed -E ' s/([A-Z\_]{3,})(\`)/xref:hammer-option-details-\L\1\E\[\1\]\2/ ' `
342+ fixed_line=` echo -e " $fixed_line " | sed -E ' s/(--\S+\s[A-Z\_]{3,})/\`\1\`/' `
332343 fixed_line=` echo -e " $fixed_line " | sed -E ' s/^(--\S+)/\`\1\`/' | sed -E ' s/( )(--\S+)/\1\`\2\`/g' `
333344 fixed_line=` echo -e " $fixed_line " | sed -E ' s/ +/ \{endash\} /' `
334345 fixed_line=" * $fixed_line "
@@ -426,9 +437,9 @@ echo -e "I: [End of input file]"
426437echo
427438
428439# Process option details
429- echo -e " Processing option details ..."
440+ echo -e " Processing data representation module ..."
430441sort $details_tmp | uniq | \
431- sed -E ' s/^([A-Z\_]+)\s+/\n\[id="hammer-option-details-\L\1\E"\]\n\ 1:: /' >> $details_file
442+ sed -E ' s/^([A-Z\_]+)\s+/\n\1:: /' >> $details_file
432443[ -n " $DEBUG " ] || rm $details_tmp # Delete tmp file
433444
434445echo
0 commit comments