Skip to content

Commit

Permalink
test(tutorial): Ensure we actually test code
Browse files Browse the repository at this point in the history
Biggest problem identified is that we are incorrectly setting the help
usage in `04_04_custom`
  • Loading branch information
epage committed Aug 9, 2022
1 parent a61f874 commit 3943ad7
Show file tree
Hide file tree
Showing 16 changed files with 102 additions and 102 deletions.
10 changes: 5 additions & 5 deletions examples/tutorial_derive/01_quick.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
```console
$ 01_quick --help
$ 01_quick_derive --help
clap [..]
A simple to use, efficient, and full-featured Command Line Argument Parser

USAGE:
01_quick[EXE] [OPTIONS] [name] [SUBCOMMAND]
01_quick_derive[EXE] [OPTIONS] [NAME] [SUBCOMMAND]

ARGS:
<name> Optional name to operate on
<NAME> Optional name to operate on

OPTIONS:
-c, --config <FILE> Sets a custom config file
Expand All @@ -23,14 +23,14 @@ SUBCOMMANDS:

By default, the program does nothing:
```console
$ 01_quick
$ 01_quick_derive
Debug mode is off

```

But you can mix and match the various features
```console
$ 01_quick -dd test
$ 01_quick_derive -dd test
Debug mode is on
Not printing testing lists...

Expand Down
14 changes: 7 additions & 7 deletions examples/tutorial_derive/02_app_settings.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
```console
$ 02_app_settings --help
$ 02_app_settings_derive --help
clap [..]
A simple to use, efficient, and full-featured Command Line Argument Parser

USAGE:
02_app_settings[EXE] --two <VALUE> --one <VALUE>
02_app_settings_derive[EXE] --two <TWO> --one <ONE>

OPTIONS:
--two <VALUE>
--one <VALUE>
-h, --help Print help information
-V, --version Print version information
--two <TWO>
--one <ONE>
-h, --help Print help information
-V, --version Print version information

$ 02_app_settings --one -1 --one -3 --two 10
$ 02_app_settings_derive --one -1 --one -3 --two 10
two: "10"
one: "-3"

Expand Down
14 changes: 7 additions & 7 deletions examples/tutorial_derive/02_apps.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
```console
$ 02_apps --help
$ 02_apps_derive --help
MyApp 1.0
Kevin K. <kbknapp@gmail.com>
Does awesome things

USAGE:
02_apps[EXE] --two <VALUE> --one <VALUE>
02_apps_derive[EXE] --two <TWO> --one <ONE>

OPTIONS:
-h, --help Print help information
--one <VALUE>
--two <VALUE>
-V, --version Print version information
-h, --help Print help information
--one <ONE>
--two <TWO>
-V, --version Print version information

$ 02_apps --version
$ 02_apps_derive --version
MyApp 1.0

```
14 changes: 7 additions & 7 deletions examples/tutorial_derive/02_crate.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
```console
$ 02_crate --help
$ 02_crate_derive --help
clap [..]
A simple to use, efficient, and full-featured Command Line Argument Parser

USAGE:
02_crate[EXE] --two <VALUE> --one <VALUE>
02_crate_derive[EXE] --two <TWO> --one <ONE>

OPTIONS:
-h, --help Print help information
--one <VALUE>
--two <VALUE>
-V, --version Print version information
-h, --help Print help information
--one <ONE>
--two <TWO>
-V, --version Print version information

$ 02_crate --version
$ 02_crate_derive --version
clap [..]

```
10 changes: 5 additions & 5 deletions examples/tutorial_derive/03_01_flag_bool.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
```console
$ 03_01_flag_bool --help
$ 03_01_flag_bool_derive --help
clap [..]
A simple to use, efficient, and full-featured Command Line Argument Parser

USAGE:
03_01_flag_bool[EXE] [OPTIONS]
03_01_flag_bool_derive[EXE] [OPTIONS]

OPTIONS:
-h, --help Print help information
-v, --verbose
-V, --version Print version information

$ 03_01_flag_bool
$ 03_01_flag_bool_derive
verbose: false

$ 03_01_flag_bool --verbose
$ 03_01_flag_bool_derive --verbose
verbose: true

$ 03_01_flag_bool --verbose --verbose
$ 03_01_flag_bool_derive --verbose --verbose
verbose: true

```
10 changes: 5 additions & 5 deletions examples/tutorial_derive/03_01_flag_count.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
```console
$ 03_01_flag_count --help
$ 03_01_flag_count_derive --help
clap [..]
A simple to use, efficient, and full-featured Command Line Argument Parser

USAGE:
03_01_flag_count[EXE] [OPTIONS]
03_01_flag_count_derive[EXE] [OPTIONS]

OPTIONS:
-h, --help Print help information
-v, --verbose
-V, --version Print version information

$ 03_01_flag_count
$ 03_01_flag_count_derive
verbose: 0

$ 03_01_flag_count --verbose
$ 03_01_flag_count_derive --verbose
verbose: 1

$ 03_01_flag_count --verbose --verbose
$ 03_01_flag_count_derive --verbose --verbose
verbose: 2

```
16 changes: 8 additions & 8 deletions examples/tutorial_derive/03_02_option.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
```console
$ 03_02_option --help
$ 03_02_option_derive --help
clap [..]
A simple to use, efficient, and full-featured Command Line Argument Parser

USAGE:
03_02_option[EXE] [OPTIONS]
03_02_option_derive[EXE] [OPTIONS]

OPTIONS:
-h, --help Print help information
-n, --name <NAME>
-V, --version Print version information

$ 03_02_option
$ 03_02_option_derive
name: None

$ 03_02_option --name bob
$ 03_02_option_derive --name bob
name: Some("bob")

$ 03_02_option --name=bob
$ 03_02_option_derive --name=bob
name: Some("bob")

$ 03_02_option -n bob
$ 03_02_option_derive -n bob
name: Some("bob")

$ 03_02_option -n=bob
$ 03_02_option_derive -n=bob
name: Some("bob")

$ 03_02_option -nbob
$ 03_02_option_derive -nbob
name: Some("bob")

```
12 changes: 6 additions & 6 deletions examples/tutorial_derive/03_03_positional.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
```console
$ 03_03_positional --help
$ 03_03_positional_derive --help
clap [..]
A simple to use, efficient, and full-featured Command Line Argument Parser

USAGE:
03_03_positional[EXE] [NAME]
03_03_positional_derive[EXE] [NAME]

ARGS:
<NAME>
Expand All @@ -13,10 +13,10 @@ OPTIONS:
-h, --help Print help information
-V, --version Print version information

$ 03_03_positional
NAME: None
$ 03_03_positional_derive
name: None

$ 03_03_positional bob
NAME: Some("bob")
$ 03_03_positional_derive bob
name: Some("bob")

```
22 changes: 11 additions & 11 deletions examples/tutorial_derive/03_04_subcommands.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
```console
$ 03_04_subcommands help
$ 03_04_subcommands_derive help
clap [..]
A simple to use, efficient, and full-featured Command Line Argument Parser

USAGE:
03_04_subcommands[EXE] <SUBCOMMAND>
03_04_subcommands_derive[EXE] <SUBCOMMAND>

OPTIONS:
-h, --help Print help information
Expand All @@ -14,12 +14,12 @@ SUBCOMMANDS:
add Adds files to myapp
help Print this message or the help of the given subcommand(s)

$ 03_04_subcommands help add
03_04_subcommands[EXE]-add [..]
$ 03_04_subcommands_derive help add
03_04_subcommands_derive[EXE]-add [..]
Adds files to myapp

USAGE:
03_04_subcommands[EXE] add [NAME]
03_04_subcommands_derive[EXE] add [NAME]

ARGS:
<NAME>
Expand All @@ -28,20 +28,20 @@ OPTIONS:
-h, --help Print help information
-V, --version Print version information

$ 03_04_subcommands add bob
$ 03_04_subcommands_derive add bob
'myapp add' was used, name is: Some("bob")

```

Because we used `command: Commands` instead of `command: Option<Commands>`:
```console
$ 03_04_subcommands
$ 03_04_subcommands_derive
? failed
clap [..]
A simple to use, efficient, and full-featured Command Line Argument Parser

USAGE:
03_04_subcommands[EXE] <SUBCOMMAND>
03_04_subcommands_derive[EXE] <SUBCOMMAND>

OPTIONS:
-h, --help Print help information
Expand All @@ -55,10 +55,10 @@ SUBCOMMANDS:

Because we added `#[clap(propagate_version = true)]`:
```console
$ 03_04_subcommands --version
$ 03_04_subcommands_derive --version
clap [..]

$ 03_04_subcommands add --version
03_04_subcommands[EXE]-add [..]
$ 03_04_subcommands_derive add --version
03_04_subcommands_derive[EXE]-add [..]

```
12 changes: 6 additions & 6 deletions examples/tutorial_derive/03_05_default_values.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
```console
$ 03_05_default_values --help
$ 03_05_default_values_derive --help
clap [..]
A simple to use, efficient, and full-featured Command Line Argument Parser

USAGE:
03_05_default_values[EXE] [NAME]
03_05_default_values_derive[EXE] [NAME]

ARGS:
<NAME> [default: alice]
Expand All @@ -13,10 +13,10 @@ OPTIONS:
-h, --help Print help information
-V, --version Print version information

$ 03_05_default_values
NAME: "alice"
$ 03_05_default_values_derive
name: "alice"

$ 03_05_default_values bob
NAME: "bob"
$ 03_05_default_values_derive bob
name: "bob"

```
10 changes: 5 additions & 5 deletions examples/tutorial_derive/04_01_enum.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
```console
$ 04_01_enum --help
$ 04_01_enum_derive --help
clap [..]
A simple to use, efficient, and full-featured Command Line Argument Parser

USAGE:
04_01_enum[EXE] <MODE>
04_01_enum_derive[EXE] <MODE>

ARGS:
<MODE> What mode to run the program in [possible values: fast, slow]
Expand All @@ -13,13 +13,13 @@ OPTIONS:
-h, --help Print help information
-V, --version Print version information

$ 04_01_enum fast
$ 04_01_enum_derive fast
Hare

$ 04_01_enum slow
$ 04_01_enum_derive slow
Tortoise

$ 04_01_enum medium
$ 04_01_enum_derive medium
? failed
error: "medium" isn't a valid value for '<MODE>'
[possible values: fast, slow]
Expand Down
8 changes: 4 additions & 4 deletions examples/tutorial_derive/04_02_parse.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
```console
$ 04_02_parse --help
$ 04_02_parse_derive --help
clap [..]
A simple to use, efficient, and full-featured Command Line Argument Parser

USAGE:
04_02_parse[EXE] <PORT>
04_02_parse_derive[EXE] <PORT>

ARGS:
<PORT> Network port to use
Expand All @@ -13,10 +13,10 @@ OPTIONS:
-h, --help Print help information
-V, --version Print version information

$ 04_02_parse 22
$ 04_02_parse_derive 22
PORT = 22

$ 04_02_parse foobar
$ 04_02_parse_derive foobar
? failed
error: Invalid value "foobar" for '<PORT>': invalid digit found in string

Expand Down
Loading

0 comments on commit 3943ad7

Please sign in to comment.