Skip to content

Commit cfbab91

Browse files
authored
doc: modified README (#7)
1 parent cc4a7cc commit cfbab91

File tree

1 file changed

+14
-17
lines changed

1 file changed

+14
-17
lines changed

README.md

+14-17
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,12 @@ This function uses `std::env::args_os` and `OsString#into_string` to read comman
3434

3535
```
3636
use cliargs::Cmd;
37+
use cliargs::errors::InvalidOsArg;
3738
3839
let cmd = match Cmd::new() {
3940
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);
4243
}
4344
};
4445
```
@@ -60,20 +61,21 @@ The `Cmd::with_os_strings` function creates a `Cmd` instance with the specified
6061

6162
```
6263
use cliargs::Cmd;
64+
use cliargs::errors::InvalidOsArg;
6365
use std::env;
6466
6567
let cmd = match Cmd::with_os_strings(env::args_os()) {
6668
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);
6971
}
7072
};
7173
```
7274

7375
### Parses without configurations
7476

7577
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.
7779

7880
Command line arguments starts with `-` or `--` are options, and others are command arguments.
7981
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
8284

8385
```
8486
use cliargs::Cmd;
87+
use cliargs::errors::InvalidOption;
8588
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![ /* ... */ ]);
9090
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()),
9996
}
10097
```
10198

0 commit comments

Comments
 (0)