Formatting of help
I wish for argbash to be able to format its help output such that it is aligned. An example is python3's output:
-u : force the stdout and stderr streams to be unbuffered;
this option has no effect on stdin; also PYTHONUNBUFFERED=x
-v : verbose (trace import statements); also PYTHONVERBOSE=x
can be supplied multiple times to increase verbosity
-V : print the Python version number and exit (also --version)
when given twice, print more information about the build
-W arg : warning control; arg is action:message:category:module:lineno
This is much easier to read than argbash's output.
Argbash has the docopt output, which is available at compile-time.
Formatting the output at script run-time is more tricky, as the general aim is to keep the bash code minimal.
What I mean is that the generated help function for a script outputs like python, not what argbash itself outputs on its own help.
In order to fix this, the following info is needed:
- Is it possible to determine the terminal width, so the output can be adjusted? I guess that this is what the Python interpreter does.
- What portable features of the
printfbuiltin can be used to use this terminal width info in bash?
- Yes.
tput colswill give you the terminal width on linux. - We can use the
%-Nsspecifier to give fixed spaces to strings, but we'll need to ensure that all printed strings fit within the length. We can use the maximum column width to align to.
If anybody could come up with a proof-of-concept Bash help function, that would be great. I can then wire it up with the Argbash core. @BourgondAries you seem to be really close with that tput and printf comments, could you maybe post a print_help prototype?
Thanks for writing argbash! I have been using it together with the interpreter hack mentioned in another issue.
The lack of this feature (as well as #147) are what is currently stopping me from using argbash in certain scripts. I wrote the following which I think does a nicer jobs of formatting the help string (though differently than suggested above). Let me know what you think. It prints stuff like the following.
This is a very very long help string that goes on seemingly without end for longer than anyone
would want it to and then it just continues even further providing the user with a great
deal of unnecessary verbosity.
Usage: ./argbash-82-proof-of-concept [--length <arg>] [-o|--option <arg>] [-e|--extraoption
<arg>] [-v|--(no-)verbose] [-h|--help] <character>
-o, --option: A option with short and long flags and default. This is a very very long
help string that goes on seemingly without end for longer than anyone would want it to
and then it just continues even further providing the user with a great deal of
unnecessary verbosity. (default: 'bool')
-e, --extraoption: A option with short and long flags and default. This is a very very
long help string that goes on seemingly without end for longer than anyone would want
it to and then it just continues even further providing the user with a great deal of
unnecessary verbosity. (default: 'bool')
-e, --extraoption: A option with short and long flags and default. This is a very very
long help string that goes on seemingly without end for longer than anyone would want
it to and then it just continues even further providing the user with a great deal of
unnecessary verbosity. (default: 'bool')
-h, --help: Prints help
See http://ix.io/4hLV for the script.