There's an endless variation on how shell scripts can present help information. Here's another, consider this array:<p><pre><code> ARGUMENTS+=(
"a,arch,Target operating system architecture (amd64)"
"b,build,Suppress building application"
"o,os,Target operating system (linux, windows, mac)"
"u,update,Java update version number (${ARG_JRE_UPDATE})"
"v,version,Full Java version (${ARG_JRE_VERSION})"
)
</code></pre>
The lines are machine-readable and alignment is computed by the template:<p><a href="https://github.com/DaveJarvis/scrivenvar/blob/master/build-template#L186" rel="nofollow">https://github.com/DaveJarvis/scrivenvar/blob/master/build-t...</a><p>When install script[0] help is requested, the following is produced:<p><pre><code> $ ./installer -h
Usage: installer [OPTIONS...]
-V, --verbose Log messages while processing
-h, --help Show this help message then exit
-a, --arch Target operating system architecture (amd64)
-b, --build Suppress building application
-o, --os Target operating system (linux, windows, mac)
-u, --update Java update version number (8)
-v, --version Full Java version (14.0.1)
</code></pre>
Using an array reduces some duplication, though more can be eliminated. Scripts typically have two places where the arguments are referenced: help and switch statements. The switch statements resemble:<p><a href="https://github.com/DaveJarvis/scrivenvar/blob/master/installer#L191" rel="nofollow">https://github.com/DaveJarvis/scrivenvar/blob/master/install...</a><p>Usually parsing arguments entails either assigning a variable or (not) performing an action later. Introducing another convention would allow hoisting the switch statement out of the installer script and into the template. Off the cuff, this could resemble:<p><pre><code> ARGUMENTS+=(
"ARG_ARCH,a,arch,Target operating system architecture (amd64)"
"do_build=noop,b,build,Suppress building application"
"ARG_JRE_OS,o,os,Target operating system (linux, windows, mac)"
"ARG_JRE_UPDATE,u,update,Java update version number (${ARG_JRE_UPDATE})"
"ARG_JRE_VERSION,v,version,Full Java version (${ARG_JRE_VERSION})"
)
</code></pre>
The instructions to execute when arguments are parsed are thus associated with the arguments themselves, in a quasi-FP style. This approach, not including the FP convention, is discussed at length in my Typesetting Markdown series[1].<p>[0]: <a href="https://github.com/DaveJarvis/scrivenvar/blob/master/installer" rel="nofollow">https://github.com/DaveJarvis/scrivenvar/blob/master/install...</a><p>[1]: <a href="https://dave.autonoma.ca/blog/2019/05/22/typesetting-markdown-part-1/" rel="nofollow">https://dave.autonoma.ca/blog/2019/05/22/typesetting-markdow...</a>