2022-04-27 20:38:08 +00:00
|
|
|
#![cfg(feature = "unstable-dynamic")]
|
|
|
|
|
2024-06-19 08:15:02 +00:00
|
|
|
use std::fs;
|
2023-08-03 18:13:49 +00:00
|
|
|
use std::path::Path;
|
|
|
|
|
2023-08-07 07:01:16 +00:00
|
|
|
use clap::{builder::PossibleValue, Command};
|
2024-05-24 15:13:50 +00:00
|
|
|
use snapbox::assert_data_eq;
|
2023-08-03 18:13:49 +00:00
|
|
|
|
|
|
|
macro_rules! complete {
|
|
|
|
($cmd:expr, $input:expr$(, current_dir = $current_dir:expr)? $(,)?) => {
|
|
|
|
{
|
|
|
|
#[allow(unused)]
|
2024-06-19 08:15:02 +00:00
|
|
|
let current_dir: Option<&Path> = None;
|
2023-08-03 18:13:49 +00:00
|
|
|
$(let current_dir = $current_dir;)?
|
|
|
|
complete(&mut $cmd, $input, current_dir)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-27 20:38:08 +00:00
|
|
|
#[test]
|
2022-04-27 20:40:24 +00:00
|
|
|
fn suggest_subcommand_subset() {
|
2023-08-03 18:13:49 +00:00
|
|
|
let mut cmd = Command::new("exhaustive")
|
|
|
|
.subcommand(Command::new("hello-world"))
|
|
|
|
.subcommand(Command::new("hello-moon"))
|
|
|
|
.subcommand(Command::new("goodbye-world"));
|
|
|
|
|
2024-07-10 14:43:58 +00:00
|
|
|
assert_data_eq!(
|
|
|
|
complete!(cmd, "he"),
|
|
|
|
snapbox::str![[r#"
|
2024-07-05 20:02:08 +00:00
|
|
|
hello-moon
|
2023-08-03 18:13:49 +00:00
|
|
|
hello-world
|
2024-07-05 20:02:08 +00:00
|
|
|
help Print this message or the help of the given subcommand(s)
|
2024-07-10 14:43:58 +00:00
|
|
|
"#]],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn suggest_hidden_long_flags() {
|
|
|
|
let mut cmd = Command::new("exhaustive")
|
|
|
|
.arg(clap::Arg::new("hello-world-visible").long("hello-world-visible"))
|
|
|
|
.arg(
|
|
|
|
clap::Arg::new("hello-world-hidden")
|
|
|
|
.long("hello-world-hidden")
|
|
|
|
.hide(true),
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_data_eq!(
|
|
|
|
complete!(cmd, "--hello-world"),
|
2024-07-10 14:46:17 +00:00
|
|
|
snapbox::str!["--hello-world-visible"]
|
2024-07-10 14:43:58 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
assert_data_eq!(
|
|
|
|
complete!(cmd, "--hello-world-h"),
|
|
|
|
snapbox::str!["--hello-world-hidden"]
|
|
|
|
)
|
2022-04-27 20:40:24 +00:00
|
|
|
}
|
|
|
|
|
2024-07-10 14:48:26 +00:00
|
|
|
#[test]
|
|
|
|
fn suggest_hidden_subcommand_and_aliases() {
|
|
|
|
let mut cmd = Command::new("exhaustive")
|
|
|
|
.subcommand(
|
|
|
|
Command::new("test_visible")
|
|
|
|
.visible_alias("test_visible-alias_visible")
|
|
|
|
.alias("test_visible-alias_hidden"),
|
|
|
|
)
|
|
|
|
.subcommand(
|
|
|
|
Command::new("test_hidden")
|
|
|
|
.visible_alias("test_hidden-alias_visible")
|
|
|
|
.alias("test_hidden-alias_hidden")
|
|
|
|
.hide(true),
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_data_eq!(
|
|
|
|
complete!(cmd, "test"),
|
|
|
|
snapbox::str![
|
2024-07-10 14:50:21 +00:00
|
|
|
"test_visible
|
2024-07-10 14:48:26 +00:00
|
|
|
test_visible-alias_visible"
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_data_eq!(
|
|
|
|
complete!(cmd, "test_h"),
|
|
|
|
snapbox::str![
|
|
|
|
"test_hidden
|
2024-07-10 14:50:21 +00:00
|
|
|
test_hidden-alias_hidden
|
2024-07-10 14:48:26 +00:00
|
|
|
test_hidden-alias_visible"
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
2024-07-10 14:50:21 +00:00
|
|
|
assert_data_eq!(
|
|
|
|
complete!(cmd, "test_hidden-alias_h"),
|
|
|
|
snapbox::str!["test_hidden-alias_hidden"]
|
|
|
|
)
|
2024-07-10 14:48:26 +00:00
|
|
|
}
|
|
|
|
|
2024-06-30 17:24:19 +00:00
|
|
|
#[test]
|
|
|
|
fn suggest_subcommand_aliases() {
|
|
|
|
let mut cmd = Command::new("exhaustive")
|
|
|
|
.subcommand(
|
|
|
|
Command::new("hello-world")
|
|
|
|
.visible_alias("hello-world-foo")
|
|
|
|
.alias("hidden-world"),
|
|
|
|
)
|
|
|
|
.subcommand(
|
|
|
|
Command::new("hello-moon")
|
|
|
|
.visible_alias("hello-moon-foo")
|
|
|
|
.alias("hidden-moon"),
|
|
|
|
)
|
|
|
|
.subcommand(
|
|
|
|
Command::new("goodbye-world")
|
|
|
|
.visible_alias("goodbye-world-foo")
|
|
|
|
.alias("hidden-goodbye"),
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_data_eq!(
|
|
|
|
complete!(cmd, "hello"),
|
|
|
|
snapbox::str![
|
|
|
|
"hello-moon
|
2024-06-30 16:50:32 +00:00
|
|
|
hello-moon-foo
|
|
|
|
hello-world
|
|
|
|
hello-world-foo"
|
2024-06-30 17:24:19 +00:00
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-07-10 14:52:24 +00:00
|
|
|
#[test]
|
|
|
|
fn suggest_hidden_possible_value() {
|
|
|
|
let mut cmd = Command::new("exhaustive").arg(
|
|
|
|
clap::Arg::new("possible_value").long("test").value_parser([
|
|
|
|
PossibleValue::new("test-visible").help("Say hello to the world"),
|
|
|
|
PossibleValue::new("test-hidden")
|
|
|
|
.help("Say hello to the moon")
|
|
|
|
.hide(true),
|
|
|
|
]),
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_data_eq!(
|
|
|
|
complete!(cmd, "--test=test"),
|
2024-07-10 14:52:53 +00:00
|
|
|
snapbox::str!["--test=test-visible\tSay hello to the world"]
|
2024-07-10 14:52:24 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
assert_data_eq!(
|
|
|
|
complete!(cmd, "--test=test-h"),
|
|
|
|
snapbox::str!["--test=test-hidden\tSay hello to the moon"]
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2024-07-10 14:43:58 +00:00
|
|
|
#[test]
|
|
|
|
fn suggest_hidden_long_flag_aliases() {
|
|
|
|
let mut cmd = Command::new("exhaustive")
|
|
|
|
.arg(
|
|
|
|
clap::Arg::new("test_visible")
|
|
|
|
.long("test_visible")
|
|
|
|
.visible_alias("test_visible-alias_visible")
|
|
|
|
.alias("test_visible-alias_hidden"),
|
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
clap::Arg::new("test_hidden")
|
|
|
|
.long("test_hidden")
|
|
|
|
.visible_alias("test_hidden-alias_visible")
|
|
|
|
.alias("test_hidden-alias_hidden")
|
|
|
|
.hide(true),
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_data_eq!(
|
|
|
|
complete!(cmd, "--test"),
|
|
|
|
snapbox::str![
|
|
|
|
"--test_visible
|
2024-07-10 14:46:17 +00:00
|
|
|
--test_visible-alias_visible"
|
2024-07-10 14:43:58 +00:00
|
|
|
]
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_data_eq!(
|
|
|
|
complete!(cmd, "--test_h"),
|
|
|
|
snapbox::str![
|
|
|
|
"--test_hidden
|
2024-07-10 14:46:17 +00:00
|
|
|
--test_hidden-alias_visible
|
|
|
|
--test_hidden-alias_hidden"
|
2024-07-10 14:43:58 +00:00
|
|
|
]
|
|
|
|
);
|
|
|
|
|
2024-07-10 14:46:17 +00:00
|
|
|
assert_data_eq!(
|
|
|
|
complete!(cmd, "--test_visible-alias_h"),
|
|
|
|
snapbox::str!["--test_visible-alias_hidden"]
|
|
|
|
);
|
2024-07-10 14:43:58 +00:00
|
|
|
|
2024-07-10 14:46:17 +00:00
|
|
|
assert_data_eq!(
|
|
|
|
complete!(cmd, "--test_hidden-alias_h"),
|
|
|
|
snapbox::str!["--test_hidden-alias_hidden"]
|
|
|
|
);
|
2024-07-10 14:43:58 +00:00
|
|
|
}
|
|
|
|
|
2022-04-27 20:40:24 +00:00
|
|
|
#[test]
|
2022-04-27 20:40:49 +00:00
|
|
|
fn suggest_long_flag_subset() {
|
2023-08-03 18:13:49 +00:00
|
|
|
let mut cmd = Command::new("exhaustive")
|
2022-04-27 20:40:49 +00:00
|
|
|
.arg(
|
|
|
|
clap::Arg::new("hello-world")
|
2022-09-02 18:11:11 +00:00
|
|
|
.long("hello-world")
|
|
|
|
.action(clap::ArgAction::Count),
|
2022-04-27 20:40:49 +00:00
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
clap::Arg::new("hello-moon")
|
2022-09-02 18:11:11 +00:00
|
|
|
.long("hello-moon")
|
|
|
|
.action(clap::ArgAction::Count),
|
2022-04-27 20:40:49 +00:00
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
clap::Arg::new("goodbye-world")
|
2022-09-02 18:11:11 +00:00
|
|
|
.long("goodbye-world")
|
|
|
|
.action(clap::ArgAction::Count),
|
2022-04-27 20:40:49 +00:00
|
|
|
);
|
|
|
|
|
2024-07-10 14:43:58 +00:00
|
|
|
assert_data_eq!(
|
|
|
|
complete!(cmd, "--he"),
|
|
|
|
snapbox::str![[r#"
|
2024-07-05 20:02:08 +00:00
|
|
|
--hello-world
|
2023-08-03 18:13:49 +00:00
|
|
|
--hello-moon
|
2024-07-05 20:02:08 +00:00
|
|
|
--help Print help
|
2024-07-10 14:43:58 +00:00
|
|
|
"#]],
|
|
|
|
);
|
2022-04-27 20:40:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2022-04-27 20:53:02 +00:00
|
|
|
fn suggest_possible_value_subset() {
|
2023-07-28 18:54:02 +00:00
|
|
|
let name = "exhaustive";
|
2023-08-03 18:13:49 +00:00
|
|
|
let mut cmd = Command::new(name).arg(clap::Arg::new("hello-world").value_parser([
|
2023-08-07 07:01:16 +00:00
|
|
|
PossibleValue::new("hello-world").help("Say hello to the world"),
|
|
|
|
"hello-moon".into(),
|
|
|
|
"goodbye-world".into(),
|
2022-04-27 20:53:02 +00:00
|
|
|
]));
|
|
|
|
|
2024-07-10 14:43:58 +00:00
|
|
|
assert_data_eq!(
|
|
|
|
complete!(cmd, "hello"),
|
|
|
|
snapbox::str![[r#"
|
2024-07-05 20:02:08 +00:00
|
|
|
hello-world Say hello to the world
|
|
|
|
hello-moon
|
2024-07-10 14:43:58 +00:00
|
|
|
"#]],
|
|
|
|
);
|
2022-04-27 20:53:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2022-04-27 20:38:08 +00:00
|
|
|
fn suggest_additional_short_flags() {
|
2023-08-03 18:13:49 +00:00
|
|
|
let mut cmd = Command::new("exhaustive")
|
2022-09-02 18:11:11 +00:00
|
|
|
.arg(
|
|
|
|
clap::Arg::new("a")
|
|
|
|
.short('a')
|
|
|
|
.action(clap::ArgAction::Count),
|
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
clap::Arg::new("b")
|
|
|
|
.short('b')
|
|
|
|
.action(clap::ArgAction::Count),
|
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
clap::Arg::new("c")
|
|
|
|
.short('c')
|
|
|
|
.action(clap::ArgAction::Count),
|
|
|
|
);
|
2022-04-27 20:38:08 +00:00
|
|
|
|
2024-07-10 14:43:58 +00:00
|
|
|
assert_data_eq!(
|
|
|
|
complete!(cmd, "-a"),
|
|
|
|
snapbox::str![[r#"
|
2024-07-05 20:02:08 +00:00
|
|
|
-aa
|
2023-08-03 18:13:49 +00:00
|
|
|
-ab
|
|
|
|
-ac
|
2024-07-05 20:02:08 +00:00
|
|
|
-ah Print help
|
2024-07-10 14:43:58 +00:00
|
|
|
"#]],
|
|
|
|
);
|
2023-08-03 18:13:49 +00:00
|
|
|
}
|
2022-04-27 20:38:08 +00:00
|
|
|
|
2023-09-25 21:10:42 +00:00
|
|
|
#[test]
|
|
|
|
fn suggest_subcommand_positional() {
|
|
|
|
let mut cmd = Command::new("exhaustive").subcommand(Command::new("hello-world").arg(
|
|
|
|
clap::Arg::new("hello-world").value_parser([
|
|
|
|
PossibleValue::new("hello-world").help("Say hello to the world"),
|
|
|
|
"hello-moon".into(),
|
|
|
|
"goodbye-world".into(),
|
|
|
|
]),
|
|
|
|
));
|
|
|
|
|
2024-07-10 14:43:58 +00:00
|
|
|
assert_data_eq!(
|
|
|
|
complete!(cmd, "hello-world [TAB]"),
|
|
|
|
snapbox::str![[r#"
|
2024-07-05 20:02:08 +00:00
|
|
|
--help Print help (see more with '--help')
|
|
|
|
-h Print help (see more with '--help')
|
|
|
|
hello-world Say hello to the world
|
2023-09-25 21:15:02 +00:00
|
|
|
hello-moon
|
2024-07-05 20:02:08 +00:00
|
|
|
goodbye-world
|
2024-07-10 14:43:58 +00:00
|
|
|
"#]],
|
|
|
|
);
|
2023-09-25 21:10:42 +00:00
|
|
|
}
|
|
|
|
|
2024-06-19 08:15:02 +00:00
|
|
|
#[test]
|
|
|
|
fn suggest_argument_value() {
|
|
|
|
let mut cmd = Command::new("dynamic")
|
|
|
|
.arg(
|
|
|
|
clap::Arg::new("input")
|
|
|
|
.long("input")
|
|
|
|
.short('i')
|
|
|
|
.value_hint(clap::ValueHint::FilePath),
|
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
clap::Arg::new("format")
|
|
|
|
.long("format")
|
|
|
|
.short('F')
|
|
|
|
.value_parser(["json", "yaml", "toml"]),
|
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
clap::Arg::new("count")
|
|
|
|
.long("count")
|
|
|
|
.short('c')
|
|
|
|
.action(clap::ArgAction::Count),
|
|
|
|
)
|
|
|
|
.arg(clap::Arg::new("positional").value_parser(["pos_a", "pos_b", "pos_c"]))
|
|
|
|
.args_conflicts_with_subcommands(true);
|
|
|
|
|
|
|
|
let testdir = snapbox::dir::DirRoot::mutable_temp().unwrap();
|
|
|
|
let testdir_path = testdir.path().unwrap();
|
|
|
|
|
|
|
|
fs::write(testdir_path.join("a_file"), "").unwrap();
|
|
|
|
fs::write(testdir_path.join("b_file"), "").unwrap();
|
|
|
|
fs::create_dir_all(testdir_path.join("c_dir")).unwrap();
|
|
|
|
fs::create_dir_all(testdir_path.join("d_dir")).unwrap();
|
|
|
|
|
|
|
|
assert_data_eq!(
|
|
|
|
complete!(cmd, "--input [TAB]", current_dir = Some(testdir_path)),
|
|
|
|
snapbox::str![
|
2024-06-29 19:04:07 +00:00
|
|
|
"a_file
|
|
|
|
b_file
|
|
|
|
c_dir/
|
|
|
|
d_dir/"
|
2024-06-19 08:15:02 +00:00
|
|
|
],
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_data_eq!(
|
|
|
|
complete!(cmd, "-i [TAB]", current_dir = Some(testdir_path)),
|
|
|
|
snapbox::str![
|
2024-06-29 19:04:07 +00:00
|
|
|
"a_file
|
|
|
|
b_file
|
|
|
|
c_dir/
|
|
|
|
d_dir/"
|
2024-06-19 08:15:02 +00:00
|
|
|
],
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_data_eq!(
|
|
|
|
complete!(cmd, "--input a[TAB]", current_dir = Some(testdir_path)),
|
2024-06-29 19:04:07 +00:00
|
|
|
snapbox::str!["a_file"],
|
2024-06-19 08:15:02 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
assert_data_eq!(
|
|
|
|
complete!(cmd, "-i b[TAB]", current_dir = Some(testdir_path)),
|
2024-06-29 19:04:07 +00:00
|
|
|
snapbox::str!["b_file"],
|
2024-06-19 08:15:02 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
assert_data_eq!(
|
|
|
|
complete!(cmd, "--format [TAB]"),
|
|
|
|
snapbox::str![
|
2024-06-29 19:04:07 +00:00
|
|
|
"json
|
|
|
|
yaml
|
|
|
|
toml"
|
2024-06-19 08:15:02 +00:00
|
|
|
],
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_data_eq!(
|
|
|
|
complete!(cmd, "-F [TAB]"),
|
|
|
|
snapbox::str![
|
2024-06-29 19:04:07 +00:00
|
|
|
"json
|
|
|
|
yaml
|
|
|
|
toml"
|
2024-06-19 08:15:02 +00:00
|
|
|
],
|
|
|
|
);
|
|
|
|
|
2024-06-29 19:04:07 +00:00
|
|
|
assert_data_eq!(complete!(cmd, "--format j[TAB]"), snapbox::str!["json"],);
|
2024-06-19 08:15:02 +00:00
|
|
|
|
2024-06-29 19:04:07 +00:00
|
|
|
assert_data_eq!(complete!(cmd, "-F j[TAB]"), snapbox::str!["json"],);
|
2024-06-19 08:15:02 +00:00
|
|
|
|
2024-06-29 19:04:07 +00:00
|
|
|
assert_data_eq!(complete!(cmd, "--format t[TAB]"), snapbox::str!["toml"],);
|
2024-06-19 08:15:02 +00:00
|
|
|
|
2024-06-29 19:04:07 +00:00
|
|
|
assert_data_eq!(complete!(cmd, "-F t[TAB]"), snapbox::str!["toml"],);
|
2024-06-19 08:15:02 +00:00
|
|
|
|
|
|
|
assert_data_eq!(
|
|
|
|
complete!(cmd, "-cccF [TAB]"),
|
|
|
|
snapbox::str![
|
2024-06-29 19:04:07 +00:00
|
|
|
"json
|
|
|
|
yaml
|
|
|
|
toml"
|
2024-06-19 08:15:02 +00:00
|
|
|
]
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_data_eq!(
|
|
|
|
complete!(cmd, "--input a_file [TAB]"),
|
|
|
|
snapbox::str![
|
|
|
|
"--input
|
|
|
|
--format
|
|
|
|
--count
|
|
|
|
--help\tPrint help
|
|
|
|
-i
|
|
|
|
-F
|
|
|
|
-c
|
2024-06-29 19:04:07 +00:00
|
|
|
-h\tPrint help
|
|
|
|
pos_a
|
|
|
|
pos_b
|
|
|
|
pos_c"
|
2024-06-19 08:15:02 +00:00
|
|
|
]
|
|
|
|
);
|
2024-06-30 13:02:18 +00:00
|
|
|
|
|
|
|
assert_data_eq!(
|
|
|
|
complete!(cmd, "-ci[TAB]", current_dir = Some(testdir_path)),
|
|
|
|
snapbox::str![
|
2024-06-30 12:59:45 +00:00
|
|
|
"-cia_file
|
|
|
|
-cib_file
|
|
|
|
-cic_dir/
|
|
|
|
-cid_dir/"
|
2024-06-30 13:02:18 +00:00
|
|
|
]
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_data_eq!(
|
|
|
|
complete!(cmd, "-ci=[TAB]", current_dir = Some(testdir_path)),
|
|
|
|
snapbox::str![
|
2024-06-30 12:59:45 +00:00
|
|
|
"-ci=a_file
|
|
|
|
-ci=b_file
|
|
|
|
-ci=c_dir/
|
|
|
|
-ci=d_dir/"
|
2024-06-30 13:02:18 +00:00
|
|
|
]
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_data_eq!(
|
|
|
|
complete!(cmd, "-ci=a[TAB]", current_dir = Some(testdir_path)),
|
2024-06-30 12:59:45 +00:00
|
|
|
snapbox::str!["-ci=a_file"]
|
2024-06-30 13:02:18 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
assert_data_eq!(
|
|
|
|
complete!(cmd, "-ciF[TAB]", current_dir = Some(testdir_path)),
|
2024-06-30 12:59:45 +00:00
|
|
|
snapbox::str![""]
|
2024-06-30 13:02:18 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
assert_data_eq!(
|
|
|
|
complete!(cmd, "-ciF=[TAB]", current_dir = Some(testdir_path)),
|
2024-06-30 12:59:45 +00:00
|
|
|
snapbox::str![""]
|
2024-06-30 13:02:18 +00:00
|
|
|
)
|
2024-06-19 08:15:02 +00:00
|
|
|
}
|
|
|
|
|
2023-08-03 18:13:49 +00:00
|
|
|
fn complete(cmd: &mut Command, args: impl AsRef<str>, current_dir: Option<&Path>) -> String {
|
|
|
|
let input = args.as_ref();
|
|
|
|
let mut args = vec![std::ffi::OsString::from(cmd.get_name())];
|
|
|
|
let arg_index;
|
|
|
|
|
|
|
|
if let Some((prior, after)) = input.split_once("[TAB]") {
|
|
|
|
args.extend(prior.split_whitespace().map(From::from));
|
|
|
|
if prior.ends_with(char::is_whitespace) {
|
2024-05-04 19:59:40 +00:00
|
|
|
args.push(std::ffi::OsString::default());
|
2023-08-03 18:13:49 +00:00
|
|
|
}
|
|
|
|
arg_index = args.len() - 1;
|
|
|
|
// HACK: this cannot handle in-word '[TAB]'
|
|
|
|
args.extend(after.split_whitespace().map(From::from));
|
|
|
|
} else {
|
|
|
|
args.extend(input.split_whitespace().map(From::from));
|
|
|
|
if input.ends_with(char::is_whitespace) {
|
2024-05-04 19:59:40 +00:00
|
|
|
args.push(std::ffi::OsString::default());
|
2023-08-03 18:13:49 +00:00
|
|
|
}
|
|
|
|
arg_index = args.len() - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
clap_complete::dynamic::complete(cmd, args, arg_index, current_dir)
|
|
|
|
.unwrap()
|
2022-04-27 20:38:08 +00:00
|
|
|
.into_iter()
|
2024-07-05 09:32:50 +00:00
|
|
|
.map(|candidate| {
|
|
|
|
let compl = candidate.get_content().to_str().unwrap();
|
|
|
|
if let Some(help) = candidate.get_help() {
|
2023-08-03 18:13:49 +00:00
|
|
|
format!("{compl}\t{help}")
|
|
|
|
} else {
|
|
|
|
compl.to_owned()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.collect::<Vec<_>>()
|
|
|
|
.join("\n")
|
2022-04-27 20:38:08 +00:00
|
|
|
}
|