@@ -34,11 +34,12 @@ This function uses `std::env::args_os` and `OsString#into_string` to read comman
34
34
35
35
```
36
36
use cliargs::Cmd;
37
+ use cliargs::errors::InvalidOsArg;
37
38
38
39
let cmd = match Cmd::new() {
39
40
Ok(cmd) => cmd,
40
- Err(cliargs::Error ::OsArgsContainInvalidUnicode { index, os_arg }) => {
41
- panic!("Invalid Unicode data: {os_arg } (index: {index })");
41
+ Err(InvalidOsArg ::OsArgsContainInvalidUnicode { index, os_arg }) => {
42
+ panic!("Invalid Unicode data: {:? } (index: {})", os_arg, index );
42
43
}
43
44
};
44
45
```
@@ -60,20 +61,21 @@ The `Cmd::with_os_strings` function creates a `Cmd` instance with the specified
60
61
61
62
```
62
63
use cliargs::Cmd;
64
+ use cliargs::errors::InvalidOsArg;
63
65
use std::env;
64
66
65
67
let cmd = match Cmd::with_os_strings(env::args_os()) {
66
68
Ok(cmd) => cmd,
67
- Err(cliargs::Error ::OsArgsContainInvalidUnicode { index, os_arg }) => {
68
- panic!("Invalid Unicode data: {os_arg } (index: {index })");
69
+ Err(InvalidOsArg ::OsArgsContainInvalidUnicode { index, os_arg }) => {
70
+ panic!("Invalid Unicode data: {:? } (index: {})", os_arg, index );
69
71
}
70
72
};
71
73
```
72
74
73
75
### Parses without configurations
74
76
75
77
The ` Cmd ` struct has the method which parses command line arguments without configurations.
76
- This function automatically divides command line arguments to options and command arguments.
78
+ This method automatically divides command line arguments to command arguments, options, and option arguments.
77
79
78
80
Command line arguments starts with ` - ` or ` -- ` are options, and others are command arguments.
79
81
If you want to specify a value to an option, follows ` "=" ` and the value after the option, like ` foo=123 ` .
@@ -82,20 +84,15 @@ All command line arguments after `--` are command arguments, even they starts wi
82
84
83
85
```
84
86
use cliargs::Cmd;
87
+ use cliargs::errors::InvalidOption;
85
88
86
- let cmd = Cmd::with_strings(vec![
87
- "path/to/app", "--foo-bar", "hoge", "--baz", "1", "-z=2", "-xyz=3", "fuga"
88
- ]);
89
-
89
+ let cmd = Cmd::with_strings(vec![ /* ... */ ]);
90
90
match cmd.parse() {
91
- Ok(_) => {},
92
- Err(cliargs::Error::InvalidOption(err)) => {
93
- match err {
94
- cliargs::Error::OptionContainsInvalidChar{ option } => { ... }
95
- _ => {}
96
- }
97
- panic!("The option: {} is invalid.", err.option());
98
- }
91
+ Ok(_) => { /* ... */ },
92
+ Err(InvalidOption::OptionContainsInvalidChar { option }) => {
93
+ panic!("Option contains invalid character: {option}");
94
+ },
95
+ Err(errr) => panic!("Invalid option: {}", err.option()),
99
96
}
100
97
```
101
98
0 commit comments