argbash icon indicating copy to clipboard operation
argbash copied to clipboard

Formatting of help

Open kstrafe opened this issue 6 years ago • 9 comments

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.

kstrafe avatar May 03 '19 11:05 kstrafe

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.

matejak avatar May 06 '19 02:05 matejak

What I mean is that the generated help function for a script outputs like python, not what argbash itself outputs on its own help.

kstrafe avatar May 06 '19 03:05 kstrafe

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 printf builtin can be used to use this terminal width info in bash?

matejak avatar Jul 25 '19 18:07 matejak

  1. Yes. tput cols will give you the terminal width on linux.
  2. We can use the %-Ns specifier 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.

kstrafe avatar Jul 25 '19 18:07 kstrafe

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?

matejak avatar Jul 12 '20 09:07 matejak

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.

djr7C4 avatar Dec 05 '22 06:12 djr7C4