Skip to content

Commit

Permalink
feat(HELP): Add a Templated Help system.
Browse files Browse the repository at this point in the history
The strategy is to copy the template from the the reader to wrapped stream
until a tag is found. Depending on its value, the appropriate content is copied
to the wrapped stream.
The copy from template is then resumed, repeating this sequence until reading
the complete template.

Tags arg given inside curly brackets:
Valid tags are:
    * `{bin}`         - Binary name.
    * `{version}`     - Version number.
    * `{author}`      - Author information.
    * `{usage}`       - Automatically generated or given usage string.
    * `{all-args}`    - Help for all arguments (options, flags, positionals arguments,
                        and subcommands) including titles.
    * `{unified}`     - Unified help for options and flags.
    * `{flags}`       - Help for flags.
    * `{options}`     - Help for options.
    * `{positionals}` - Help for positionals arguments.
    * `{subcommands}` - Help for subcommands.
    * `{after-help}`  - Help for flags.
  • Loading branch information
hgrecco committed Apr 13, 2016
1 parent 04b5b07 commit 81e121e
Show file tree
Hide file tree
Showing 7 changed files with 465 additions and 86 deletions.
24 changes: 24 additions & 0 deletions benches/04_new_help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,3 +341,27 @@ fn example10_new(b: &mut Bencher) {
let app = example10();
b.iter(|| build_new_help(&app));
}

#[bench]
fn example4_template(b: &mut Bencher) {
/*
MyApp 1.0
Kevin K. <[email protected]>
Parses an input file to do awesome things
USAGE:
test [FLAGS] <input>
FLAGS:
-c, --config sets the config file to use
-d, --debug turn on debugging information
-h, --help Prints help information
-V, --version Prints version information
ARGS:
<input> the input file to use
*/

let app = example4().template("{bin} {version}\n{author}\n{about}\n\nUSAGE:\n {usage}\n\nFLAGS:\n{flags}\n\nARGS:\n{args}\n");
b.iter(|| build_new_help(&app));
}
Loading

0 comments on commit 81e121e

Please sign in to comment.