Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Formatting of help #82

Open
kstrafe opened this issue May 3, 2019 · 6 comments
Open

Formatting of help #82

kstrafe opened this issue May 3, 2019 · 6 comments
Labels
help wanted proposal PRs wanted This issue is not likely to get addressed, unless you make a PR.

Comments

@kstrafe
Copy link

kstrafe commented May 3, 2019

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.

@matejak
Copy link
Owner

matejak commented May 6, 2019

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.

@kstrafe
Copy link
Author

kstrafe commented May 6, 2019

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

@matejak
Copy link
Owner

matejak commented Jul 25, 2019

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?

@kstrafe
Copy link
Author

kstrafe commented Jul 25, 2019

  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.

@matejak matejak added the PRs wanted This issue is not likely to get addressed, unless you make a PR. label Jul 12, 2020
@matejak
Copy link
Owner

matejak commented Jul 12, 2020

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?

@djr7C4
Copy link

djr7C4 commented Dec 5, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted proposal PRs wanted This issue is not likely to get addressed, unless you make a PR.
Projects
None yet
Development

No branches or pull requests

3 participants