CLI11 icon indicating copy to clipboard operation
CLI11 copied to clipboard

Add an optional extra "long help" message argument to App (and subcommands)

Open certik opened this issue 5 years ago • 2 comments

Right now one can create a subcommand as follows:

CLI::App &fmt = *app.add_subcommand("fmt", "Format the input files and modifies them in-place.");
fmt.add_option("file", arg_fmt_file, "Source file to format in-place")->required();
fmt.add_option("--spaces", arg_fmt_indent, "Number of spaces to use for indentation", true);
...

Which translates to the following help messages:

$ lfortran -h
...
Subcommands:
  fmt                    Format the input files and modifies them in-place.

$ lfortran fmt -h
Format the input files and modifies them in-place.
Usage: lfortran fmt [OPTIONS] file

Positionals:
  file TEXT REQUIRED     Source file to format in-place

Options:
  -h,--help              Print this help message and exit
  --spaces INT=4         Number of spaces to use for indentation
  --indent-in-sub        Indent statements in subroutines / functions
  --indent-in-mod        Indent subroutines / functions in modules
  --show                 Show the formatted output, do not modify the original file
  --no-color             Do not "--show" source code in color

The current default help message is the "short help", which is displayed in the main app, and it is a good habit to fit on one line to be usable. Then this message is also shown at the top of the subcommand help on one line.

However, in addition to "short help", I would also like to provide a "long help" message, that would show in the subcommand help as follows:

$ lfortran fmt -h
Format the input files and modifies them in-place.

Usage: lfortran fmt [OPTIONS] file

If <file> is given, it reformats the files. If -i is specified
together with <file>, the files are edited in-place. Otherwise, the
result is written to the standard output.

Positionals:
  file TEXT REQUIRED     Source file to format in-place

Options:
  -h,--help              Print this help message and exit
  --spaces INT=4         Number of spaces to use for indentation
  --indent-in-sub        Indent statements in subroutines / functions
  --indent-in-mod        Indent subroutines / functions in modules
  --show                 Show the formatted output, do not modify the original file
  --no-color             Do not "--show" source code in color

The code to achieve it could be something like:

CLI::App &fmt = *app.add_subcommand("fmt", "Format the input files and modifies them in-place.", "If <file> is given, it reformats the files. If -i is specified\ntogether with <file>, the files are edited in-place. Otherwise, the\nresult is written to the standard output.");

Is this already possible with CLI11, and if not, would you be open to such a functionality?

certik avatar Aug 31 '20 15:08 certik

Maybe implement a ->header() to complement the already existing ->footer() ?

jakoblover avatar Sep 02 '20 07:09 jakoblover