Skip to content

Commit

Permalink
test: Test for options like -xx
Browse files Browse the repository at this point in the history
  • Loading branch information
ysthakur committed Oct 28, 2023
1 parent 27e7c64 commit bbb7934
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 9 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,4 @@ Things to do:
- Add .gz files to the tests folder
- Test excluding/including commands and directories
- Figure out why fish only seems to use man1, man6, and man8
- Handle options like `-vv` and `-/` in Nushell
11 changes: 8 additions & 3 deletions src/parse/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,18 +107,23 @@ pub fn make_flag(options: &str, desc: Option<&str>) -> Option<Flag> {
let delim = Regex::new(r#"[ ,="|]"#).unwrap();
for option in delim.split(options) {
let option = Regex::new(r"\[.*\]").unwrap().replace(option, "");
// todo Fish doesn't replace <.*> so maybe this is wrong
// todo Fish doesn't replace <.*> or (.*) so maybe this is wrong
let option = Regex::new(r"<.*").unwrap().replace(&option, "");
// todo this is ridiculously verbose
let option = option
.trim_matches(" \t\r\n[](){}.:!".chars().collect::<Vec<_>>().as_slice());
// TODO in future, handle stuff like `--no-[to|cc|bc]` (example from `git
// send-email`)
// Trim stuff like `-[foo` and `-)foo` from the end
// Something like `--foo=(+|\-)x` would otherwise be read as --foo and -x
let option = Regex::new(r"-[()\[\]].*$").unwrap().replace(option, "");
if !option.starts_with('-') || option == "-" || option == "--" {
continue;
}
if Regex::new(r"\{\}\(\)").unwrap().is_match(option) {
if Regex::new(r"\{\}\(\)").unwrap().is_match(&option) {
continue;
}
forms.push(option.to_owned());
forms.push(option.to_string());
}

if forms.is_empty() {
Expand Down
2 changes: 1 addition & 1 deletion tests/resources/expected/_test1.bash

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/resources/expected/_test1.zsh

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion tests/resources/expected/test1-completions.nu

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/resources/in/man1/test1-sub1-nested.1

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions tests/resources/in/man1/test1-sub2.1

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit bbb7934

Please sign in to comment.