(the script itself is of no use to you since it only talks to a piece of hardware)
The command dispatcher case statement and all the embedded help is in do_cmd() at 2857, and the help reader is help() at 425
I like their explicit #args vs #help
One jank in mine is I have a verbosity level setting which affects most messages, and help() uses it to filter some of the help. Normal verbosity shows only the normal help for the normal commands. If verbosity is set higher, then help() shows more commands.
The way that's implimented in help() is extra comments that change the behavior of help() as it's scanning the file from top to bottom.
When it hits a '#v 2' it starts only displaying the help if the user has currently set verbosity>=2 until further notice. Later down the file it hits a '#v 1' and starts displaying help again...
It works but it feels kind of 70's or assembly.
#v 1
#h normal help for mortals
#h ...
#v 2
#h don't confuse the simple folk with this dangerous powerful stuff...
#h ...
#v 1
#h a few more normal commands
#h ...
#v 0
#h display this even the user has set verbosity to 0 to request silence
#h ...
I mean, this is basically all of Bash lol. A very clever idea that has endured since the 70's but also shows it... And yet we get obsessed with "writing perfect Bash" still.
The amazing thing is that there are also old "functional shells" like es-shell https://wryun.github.io/es-shell/ (he still works on this and it is indeed very interesting!)
I've had some form of `grep '^#h ' $0` in most of my scripts forever.
This one is a purity stunt and doesn't use grep, or anything else: https://github.com/bkw777/pdd.sh
(the script itself is of no use to you since it only talks to a piece of hardware)
The command dispatcher case statement and all the embedded help is in do_cmd() at 2857, and the help reader is help() at 425
I like their explicit #args vs #help
One jank in mine is I have a verbosity level setting which affects most messages, and help() uses it to filter some of the help. Normal verbosity shows only the normal help for the normal commands. If verbosity is set higher, then help() shows more commands.
The way that's implimented in help() is extra comments that change the behavior of help() as it's scanning the file from top to bottom.
When it hits a '#v 2' it starts only displaying the help if the user has currently set verbosity>=2 until further notice. Later down the file it hits a '#v 1' and starts displaying help again...
It works but it feels kind of 70's or assembly.