You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+41-11
Original file line number
Diff line number
Diff line change
@@ -10,7 +10,7 @@ This library provides the following functionalities:
10
10
- This library supports not `-ofoo` but `-o=foo` as an alternative to `-o foo` for short option.
11
11
- Supports parsing with option configurations.
12
12
- Supports parsing with option configurations made from struct fields and attributes, and setting the option values to them.
13
-
-Is able to parse command line arguments including sub commands.*(To be added)*
13
+
-Supports parsing command line arguments including sub commands.
14
14
- Generates help text from option configurations.
15
15
16
16
## Install
@@ -32,7 +32,7 @@ The usage of this `Cmd` struct is as follows:
32
32
The `Cmd::new` function creates a `Cmd` instance with original command line arguments.
33
33
This function uses `std::env::args_os` and `OsString#into_string` to read command line arguments in order to avoid `panic!` call that the user cannot control.
34
34
35
-
```
35
+
```rust
36
36
usecliargs::Cmd;
37
37
usecliargs::errors::InvalidOsArg;
38
38
@@ -48,7 +48,7 @@ let cmd = match Cmd::new() {
48
48
49
49
The `Cmd::with_strings` function creates a `Cmd` instance with the specified `String` array.
50
50
51
-
```
51
+
```rust
52
52
usecliargs::Cmd;
53
53
usestd::env;
54
54
@@ -59,7 +59,7 @@ let cmd = Cmd::with_strings(env::args());
59
59
60
60
The `Cmd::with_os_strings` function creates a `Cmd` instance with the specified `OsString` array.
61
61
62
-
```
62
+
```rust
63
63
usecliargs::Cmd;
64
64
usecliargs::errors::InvalidOsArg;
65
65
usestd::env;
@@ -82,7 +82,7 @@ If you want to specify a value to an option, follows `"="` and the value after t
82
82
83
83
All command line arguments after `--` are command arguments, even they starts with `-` or `--`.
84
84
85
-
```
85
+
```rust
86
86
usecliargs::Cmd;
87
87
usecliargs::errors::InvalidOption;
88
88
@@ -108,7 +108,7 @@ If this field is not specified, the first element of `names` field is used inste
108
108
109
109
`names` field is a string array and specified the option names, that are both long options and short options.
110
110
The order of elements in this field is used in a help text.
111
-
If you want to prioritize the output of short option name first in the help text, like `-f, --foo-bar`, but use the long option name as the key in the option map, write `store_key` and `names` fields as follows: `OptCfg::with(&[store_key("foo-bar"), names(&["f", "foo-bar"])])`.
111
+
If you want to prioritize the output of short option name first in the help text, like `-f, --foo-bar`, but use the long option name as the key in the option map, write `store_key` and `names` fields as follows: `OptCfg::with([store_key("foo-bar"), names(&["f", "foo-bar"])])`.
112
112
113
113
`has_arg` field indicates the option requires one or more values.
114
114
`is_array` field indicates the option can have multiple values.
@@ -125,19 +125,19 @@ If you want to access the option configurations after parsing, get them from thi
125
125
126
126
In addition,the help printing for an array of `OptCfg` is generated with `Help`.
If you want to specify an array which contains only one emtpy string, write nothing after
212
212
`=` symbol, like `#[opt(cfg="=")]`.
213
213
214
-
```
214
+
```rust
215
215
usecliargs::Cmd;
216
216
usecliargs::errors::InvalidOption;
217
217
@@ -249,11 +249,41 @@ help.print();
249
249
// -z, --baz <s> This is description of baz.
250
250
```
251
251
252
+
### Supports parsing command line arguments including sub commands
253
+
254
+
This crate provides methods `Cmd#parse_until_sub_cmd`, `Cmd#parse_until_sub_cmd_with`, and `Cmd#parse_until_sub_cmd_for` for parsing command line arguments including sub commands.
255
+
256
+
These methods correspond to `Cmd#parse`, `Cmd#parse_with`, and `Cmd#parse_for`, respectively, and behave the same except that they stop parsing before the first command argument (= sub command) and return a `Cmd` instance containing the arguments starting from the the sub command.
257
+
258
+
The folowing is an example code using `Cmd#parse_until_sub_cmd`:
0 commit comments