Skip to content

Commit

Permalink
Merge pull request #15 from andrey-zherikov/help-example
Browse files Browse the repository at this point in the history
Improve help example
  • Loading branch information
andrey-zherikov authored Nov 28, 2021
2 parents 1a61f28 + 486c5fc commit 32801c2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,8 @@ Here is an example of how this customization can be used:
struct T
{
@NamedArgument string s;
@(NamedArgument.Placeholder("VALUE")) string p;
@(NamedArgument.HideFromHelp()) string hidden;
enum Fruit { apple, pear };
Expand All @@ -531,7 +533,7 @@ parseCLIArgs!T(["-h"]);

This example will print the following help message:
```
usage: MYPROG [-s S] -f {apple,pear} [-i {1,4,16,8}] [-h] param0 {q,a}
usage: MYPROG [-s S] [-p VALUE] -f {apple,pear} [-i {1,4,16,8}] [-h] param0 {q,a}
custom description
Expand All @@ -547,6 +549,7 @@ Required arguments:
Optional arguments:
-s S
-p VALUE
-i {1,4,16,8}
-h, --help Show this help message and exit
Expand Down
7 changes: 5 additions & 2 deletions source/argparse.d
Original file line number Diff line number Diff line change
Expand Up @@ -3148,6 +3148,8 @@ unittest
struct T
{
@NamedArgument string s;
@(NamedArgument.Placeholder("VALUE")) string p;

@(NamedArgument.HideFromHelp()) string hidden;

enum Fruit { apple, pear };
Expand All @@ -3172,8 +3174,8 @@ unittest
static assert(test!printUsage.length > 0); // ensure that it works at compile time
static assert(test!printHelp .length > 0); // ensure that it works at compile time

assert(test!printUsage == "usage: MYPROG [-s S] -f {apple,pear} [-i {1,4,16,8}] [-h] param0 {q,a}\n");
assert(test!printHelp == "usage: MYPROG [-s S] -f {apple,pear} [-i {1,4,16,8}] [-h] param0 {q,a}\n\n"~
assert(test!printUsage == "usage: MYPROG [-s S] [-p VALUE] -f {apple,pear} [-i {1,4,16,8}] [-h] param0 {q,a}\n");
assert(test!printHelp == "usage: MYPROG [-s S] [-p VALUE] -f {apple,pear} [-i {1,4,16,8}] [-h] param0 {q,a}\n\n"~
"custom description\n\n"~
"Required arguments:\n"~
" -f {apple,pear}, --fruit {apple,pear}\n"~
Expand All @@ -3186,6 +3188,7 @@ unittest
" {q,a} \n\n"~
"Optional arguments:\n"~
" -s S \n"~
" -p VALUE \n"~
" -i {1,4,16,8} \n"~
" -h, --help Show this help message and exit\n\n"~
"custom epilog\n");
Expand Down

0 comments on commit 32801c2

Please sign in to comment.