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

Add the option to add text before and after help output #72

Merged
merged 3 commits into from
Jan 3, 2020

Conversation

CrustyAuklet
Copy link
Contributor

It would be nice to add text to the beginning and end of help messages. Many standard *nix tools do this to provide examples, show license information, etc.

For example, the current help output on a firmware programmer I am building:

Usage: dev-program [options] FILE

Positional arguments:
FILE                    HEX input file

Optional arguments:
-h --help               show this help message and exit
-l --list-interfaces    List all possible programming interfaces detectable by this program
-d --delay              Amount of time to wait for a device reset for programming, in milliseconds (default 5000)
-r --auto-reset         Attempt to automatically reset the device (depends on programming cable and/or current firmware)

Turns into:

Usage: dev-program [options] FILE
Internal Device Programmer Version 0.1.0

Examples:
    dev-program -w -v image.hex  # Write image.hex to the device and verify
    dev-program -l               # List all potential programming devices

Positional arguments:
FILE                    HEX input file

Optional arguments:
-h --help               show this help message and exit
-l --list-interfaces    List all possible programming interfaces detectable by this program
-d --delay              Amount of time to wait for a device reset for programming, in milliseconds (default 5000)
-r --auto-reset         Attempt to automatically reset the device (depends on programming cable and/or current firmware)

Please contact [email protected] with any questions
Submit any bugs at https://gitlab.company.com/dev-program/issues

To add this I added two new string members, and printed them out if they are not empty during the help output. I tried to make sure the formatting remains unchanged if the text is not used. The spacing when used I attempted to make it look like the output of ls -help and others.

I did this quickly because I needed it for this current project, so totally open to any suggestions to make it better, or rejection if you don't think it is in scope for your project.

add variables, assignment functions, and printing for text before and after the argument lists.
include/argparse.hpp Outdated Show resolved Hide resolved
@CrustyAuklet
Copy link
Contributor Author

In my haste I didn't think of the obvious, and check against python argparse. looking now I noticed that python argparse prints the description like this:

usage: argparse.py [-h]

A foo that bars

optional arguments:
 -h, --help  show this help message and exit

And that's how you'd foo a bar

currently I am missing the space above the description because I modeled it after ls:

Usage: ls [OPTION]... [FILE]...
List information about the FILEs (the current directory by default).
Sort entries alphabetically if none of -cftuvSUX nor --sort is specified.

Mandatory arguments to long options are mandatory for short options too.
  -a, --all                  do not ignore entries starting with .
  -A, --almost-all           do not list implied . and ..

Would you like the extra space to make it more like the python output?

@p-ranav
Copy link
Owner

p-ranav commented Jan 2, 2020

Yeah let's add it. Thanks!

@p-ranav p-ranav merged commit f01beb8 into p-ranav:master Jan 3, 2020
@p-ranav
Copy link
Owner

p-ranav commented Jan 3, 2020

Thanks for your contribution!

@CrustyAuklet CrustyAuklet deleted the text-pre-post branch January 3, 2020 03:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants