Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

There's an endless variation on how shell scripts can present help information. Here's another, consider this array:

    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})"
    )
The lines are machine-readable and alignment is computed by the template:

https://github.com/DaveJarvis/scrivenvar/blob/master/build-t...

When install script[0] help is requested, the following is produced:

    $ ./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)
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:

https://github.com/DaveJarvis/scrivenvar/blob/master/install...

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:

    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})"
    )
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].

[0]: https://github.com/DaveJarvis/scrivenvar/blob/master/install...

[1]: https://dave.autonoma.ca/blog/2019/05/22/typesetting-markdow...



Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: