Skip to content

Commit

Permalink
refactor: change @meta syntax (#252)
Browse files Browse the repository at this point in the history
```
# @meta <key> [value]
```
  • Loading branch information
sigoden authored Oct 1, 2023
1 parent 8f74589 commit d42366b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ COMMANDS:
test Run tests [aliases: t, tst]
```

### Meta
### @describe @version @author

- @describe: Sets the cli’s description.
- @version: Sets cli's version.
Expand Down Expand Up @@ -227,6 +227,21 @@ COMMANDS:
test Run test
```

### @meta

```
@meta <key> [value]
```

Add metadata

#### Builtin Metadata

| syntax | scope | description |
| -------------------- | ----- | --------------------------------------------------------- |
| combine-shorts | root | Short flags can be combined, e.g. `-xf => -x -f ` |
| inherit-flag-options | root | All subcommands inherit flag/options from parent command. |

### Value Notation

Value notation is used to describe value type of options and positional parameters.
Expand Down
12 changes: 4 additions & 8 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -524,13 +524,9 @@ fn parse_tail(input: &str) -> nom::IResult<&str, &str> {

fn parse_key_value(input: &str) -> nom::IResult<&str, Option<(&str, &str)>> {
let input = input.trim_end();
let key_value = alt((
map(
separated_pair(parse_name, char('='), terminated(parse_default_value, eof)),
|(key, value)| Some((key, value)),
),
map(terminated(parse_name, eof), |key| Some((key, ""))),
));
let key_value = map(pair(parse_name, parse_tail), |(key, value)| {
Some((key, value))
});

alt((key_value, success(None)))(input)
}
Expand Down Expand Up @@ -925,7 +921,7 @@ mod tests {
assert_token!("# @version 1.0.0", Version, "1.0.0");
assert_token!("# @author Somebody", Author, "Somebody");
assert_token!("# @meta key", Meta, "key", "");
assert_token!("# @meta key=value", Meta, "key", "value");
assert_token!("# @meta key value", Meta, "key", "value");
assert_token!("# @cmd A subcommand", Cmd, "A subcommand");
assert_token!("# @alias tst", Aliases, ["tst"]);
assert_token!("# @alias t,tst", Aliases, ["t", "tst"]);
Expand Down

0 comments on commit d42366b

Please sign in to comment.