1
0
mirror of https://github.com/BurntSushi/ripgrep.git synced 2025-11-23 21:54:45 +02:00

complete: improvements for the --hyperlink-format flag

The goal is to make the completion for `rg --hyperlink-format v<TAB>`
work in the fish shell.

These are not exhaustive (the user can also specify custom formats).
This is somewhat unfortunate, but is probably better than not doing
anything at all.

The `grep+` value necessitated a change to a test.

Closes #3096
This commit is contained in:
Ilya Grigoriev
2025-07-06 16:05:15 -07:00
committed by Andrew Gallant
parent 66aa4a63bb
commit 519c1bd5cf
2 changed files with 18 additions and 2 deletions

View File

@@ -3008,6 +3008,19 @@ https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda
&DOC
}
fn doc_choices(&self) -> &'static [&'static str] {
static CHOICES: LazyLock<Vec<String>> = LazyLock::new(|| {
let mut aliases = grep::printer::hyperlink_aliases();
aliases.sort_by_key(|alias| {
alias.display_priority().unwrap_or(i16::MAX)
});
aliases.iter().map(|alias| alias.name().to_string()).collect()
});
static BORROWED: LazyLock<Vec<&'static str>> =
LazyLock::new(|| CHOICES.iter().map(|name| &**name).collect());
&*BORROWED
}
fn update(&self, v: FlagValue, args: &mut LowArgs) -> anyhow::Result<()> {
let v = v.unwrap_value();
let string = convert::str(&v)?;
@@ -7724,9 +7737,10 @@ mod tests {
assert!(
choice.chars().all(|c| c.is_ascii_alphanumeric()
|| c == '-'
|| c == ':'),
|| c == ':'
|| c == '+'),
"choice '{choice}' for flag '{long}' does not match \
^[-:0-9A-Za-z]+$",
^[-+:0-9A-Za-z]+$",
)
}
}