Skip to content

Commit

Permalink
Merge pull request #5 from aminya/fixes
Browse files Browse the repository at this point in the history
Fix the quick example
  • Loading branch information
burner authored Aug 25, 2021
2 parents d17de55 + cd3dd7f commit 713e772
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
18 changes: 14 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ A command line and config file parser for DLang

## Quick Example
```d
import args: Args, Optional, parseArgsWithConfigFile, printArgsHelp;
import args : Arg, Optional, parseArgsWithConfigFile, printArgsHelp;
static struct MyOptions {
@Arg("the input file", Optional.no) string inputFilename;
@Arg("test values", 'b') int[] testValues;
@Arg("the input file", Optional.yes) string inputFilename;
@Arg("test values", 't') int[] testValues;
@Arg("Enable feature") bool enableFeature;
}
Expand All @@ -18,7 +18,7 @@ MyOptions getOptions(ref string[] args) {
bool helpWanted = parseArgsWithConfigFile(options, args);
if(helpWanted) {
if (helpWanted) {
printArgsHelp(options, "A text explaining the program");
}
return options;
Expand All @@ -31,6 +31,16 @@ void main(string[] args) {
}
```

This gives:
```ps1
❯ ./quick_example --help
A text explaining the program
--inputFilename Type: dchar[] default: Help: the input file
-t --testValues Type: int[] default: [] Help: test values
--enableFeature Type: bool default: false Help: Enable feature
```

## Explanation

`argsd` arguments are structures as shown below.
Expand Down
24 changes: 24 additions & 0 deletions quick_example.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import args : Arg, Optional, parseArgsWithConfigFile, printArgsHelp;

static struct MyOptions {
@Arg("the input file", Optional.yes) string inputFilename;
@Arg("test values", 't') int[] testValues;
@Arg("Enable feature") bool enableFeature;
}

MyOptions getOptions(ref string[] args) {
MyOptions options;

bool helpWanted = parseArgsWithConfigFile(options, args);

if (helpWanted) {
printArgsHelp(options, "A text explaining the program");
}
return options;
}

void main(string[] args) {
const options = getOptions(args); // or args.dup to keep the original args

// use options here....
}

0 comments on commit 713e772

Please # to comment.