2021-10-06 23:33:06 +00:00
|
|
|
use super::*;
|
2021-10-08 00:54:14 +00:00
|
|
|
use crate::Fig;
|
2021-10-06 23:33:06 +00:00
|
|
|
|
|
|
|
fn build_app() -> App<'static> {
|
|
|
|
build_app_with_name("myapp")
|
|
|
|
}
|
|
|
|
|
|
|
|
fn build_app_with_name(s: &'static str) -> App<'static> {
|
|
|
|
App::new(s)
|
2021-10-11 15:49:55 +00:00
|
|
|
.version("3.0")
|
2021-10-12 18:59:56 +00:00
|
|
|
.setting(AppSettings::PropagateVersion)
|
2021-10-06 23:33:06 +00:00
|
|
|
.about("Tests completions")
|
|
|
|
.arg(
|
|
|
|
Arg::new("file")
|
|
|
|
.value_hint(ValueHint::FilePath)
|
2021-11-18 16:17:15 +00:00
|
|
|
.help("some input file"),
|
2021-10-06 23:33:06 +00:00
|
|
|
)
|
|
|
|
.subcommand(
|
|
|
|
App::new("test").about("tests things").arg(
|
|
|
|
Arg::new("case")
|
|
|
|
.long("case")
|
|
|
|
.takes_value(true)
|
2021-11-18 16:17:15 +00:00
|
|
|
.help("the case to test"),
|
2021-10-06 23:33:06 +00:00
|
|
|
),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn fig() {
|
|
|
|
let mut app = build_app();
|
2021-10-12 12:57:26 +00:00
|
|
|
common(Fig, &mut app, "myapp", FIG);
|
2021-10-06 23:33:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static FIG: &str = r#"const completion: Fig.Spec = {
|
|
|
|
name: "myapp",
|
|
|
|
description: "Tests completions",
|
|
|
|
subcommands: [
|
|
|
|
{
|
|
|
|
name: "test",
|
|
|
|
description: "tests things",
|
|
|
|
options: [
|
|
|
|
{
|
|
|
|
name: "--case",
|
|
|
|
description: "the case to test",
|
|
|
|
args: {
|
|
|
|
name: "case",
|
|
|
|
isOptional: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2021-10-12 14:08:22 +00:00
|
|
|
name: ["-h", "--help"],
|
|
|
|
description: "Print help information",
|
2021-10-06 23:33:06 +00:00
|
|
|
},
|
2021-10-11 15:49:55 +00:00
|
|
|
{
|
|
|
|
name: ["-V", "--version"],
|
|
|
|
description: "Print version information",
|
|
|
|
},
|
2021-10-06 23:33:06 +00:00
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "help",
|
|
|
|
description: "Print this message or the help of the given subcommand(s)",
|
|
|
|
options: [
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
options: [
|
|
|
|
{
|
|
|
|
name: ["-h", "--help"],
|
|
|
|
description: "Print help information",
|
|
|
|
},
|
2021-10-11 15:49:55 +00:00
|
|
|
{
|
|
|
|
name: ["-V", "--version"],
|
|
|
|
description: "Print version information",
|
|
|
|
},
|
2021-10-06 23:33:06 +00:00
|
|
|
],
|
|
|
|
args: {
|
|
|
|
name: "file",
|
|
|
|
isOptional: true,
|
|
|
|
template: "filepaths",
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
export default completion;
|
|
|
|
"#;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn fig_with_special_commands() {
|
|
|
|
let mut app = build_app_special_commands();
|
2021-10-12 12:57:26 +00:00
|
|
|
common(Fig, &mut app, "my_app", FIG_SPECIAL_CMDS);
|
2021-10-06 23:33:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn build_app_special_commands() -> App<'static> {
|
|
|
|
build_app_with_name("my_app")
|
|
|
|
.subcommand(
|
|
|
|
App::new("some_cmd").about("tests other things").arg(
|
|
|
|
Arg::new("config")
|
|
|
|
.long("--config")
|
|
|
|
.takes_value(true)
|
2021-11-18 16:17:15 +00:00
|
|
|
.help("the other case to test"),
|
2021-10-06 23:33:06 +00:00
|
|
|
),
|
|
|
|
)
|
2021-10-19 01:38:22 +00:00
|
|
|
.subcommand(App::new("some-cmd-with-hyphens").alias("hyphen"))
|
2021-10-06 23:33:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static FIG_SPECIAL_CMDS: &str = r#"const completion: Fig.Spec = {
|
|
|
|
name: "my_app",
|
|
|
|
description: "Tests completions",
|
|
|
|
subcommands: [
|
|
|
|
{
|
|
|
|
name: "test",
|
|
|
|
description: "tests things",
|
|
|
|
options: [
|
|
|
|
{
|
|
|
|
name: "--case",
|
|
|
|
description: "the case to test",
|
|
|
|
args: {
|
|
|
|
name: "case",
|
|
|
|
isOptional: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2021-10-12 14:08:22 +00:00
|
|
|
name: ["-h", "--help"],
|
|
|
|
description: "Print help information",
|
2021-10-06 23:33:06 +00:00
|
|
|
},
|
2021-10-11 15:49:55 +00:00
|
|
|
{
|
|
|
|
name: ["-V", "--version"],
|
|
|
|
description: "Print version information",
|
|
|
|
},
|
2021-10-06 23:33:06 +00:00
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "some_cmd",
|
|
|
|
description: "tests other things",
|
|
|
|
options: [
|
|
|
|
{
|
|
|
|
name: "--config",
|
|
|
|
description: "the other case to test",
|
|
|
|
args: {
|
|
|
|
name: "config",
|
|
|
|
isOptional: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2021-10-12 14:08:22 +00:00
|
|
|
name: ["-h", "--help"],
|
|
|
|
description: "Print help information",
|
2021-10-06 23:33:06 +00:00
|
|
|
},
|
2021-10-11 15:49:55 +00:00
|
|
|
{
|
|
|
|
name: ["-V", "--version"],
|
|
|
|
description: "Print version information",
|
|
|
|
},
|
2021-10-06 23:33:06 +00:00
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
2021-10-19 01:38:22 +00:00
|
|
|
name: "some-cmd-with-hyphens",
|
2021-10-06 23:33:06 +00:00
|
|
|
options: [
|
|
|
|
{
|
2021-10-12 14:08:22 +00:00
|
|
|
name: ["-h", "--help"],
|
|
|
|
description: "Print help information",
|
2021-10-06 23:33:06 +00:00
|
|
|
},
|
2021-10-11 15:49:55 +00:00
|
|
|
{
|
|
|
|
name: ["-V", "--version"],
|
|
|
|
description: "Print version information",
|
|
|
|
},
|
2021-10-06 23:33:06 +00:00
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "help",
|
|
|
|
description: "Print this message or the help of the given subcommand(s)",
|
|
|
|
options: [
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
options: [
|
|
|
|
{
|
|
|
|
name: ["-h", "--help"],
|
|
|
|
description: "Print help information",
|
|
|
|
},
|
2021-10-11 15:49:55 +00:00
|
|
|
{
|
|
|
|
name: ["-V", "--version"],
|
|
|
|
description: "Print version information",
|
|
|
|
},
|
2021-10-06 23:33:06 +00:00
|
|
|
],
|
|
|
|
args: {
|
|
|
|
name: "file",
|
|
|
|
isOptional: true,
|
|
|
|
template: "filepaths",
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
export default completion;
|
|
|
|
"#;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn fig_with_special_help() {
|
|
|
|
let mut app = build_app_special_help();
|
2021-10-12 12:57:26 +00:00
|
|
|
common(Fig, &mut app, "my_app", FIG_SPECIAL_HELP);
|
2021-10-06 23:33:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn build_app_special_help() -> App<'static> {
|
|
|
|
App::new("my_app")
|
2021-10-11 15:49:55 +00:00
|
|
|
.version("3.0")
|
2021-10-06 23:33:06 +00:00
|
|
|
.arg(
|
|
|
|
Arg::new("single-quotes")
|
|
|
|
.long("single-quotes")
|
2021-11-18 16:17:15 +00:00
|
|
|
.help("Can be 'always', 'auto', or 'never'"),
|
2021-10-06 23:33:06 +00:00
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::new("double-quotes")
|
|
|
|
.long("double-quotes")
|
2021-11-18 16:17:15 +00:00
|
|
|
.help("Can be \"always\", \"auto\", or \"never\""),
|
2021-10-06 23:33:06 +00:00
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::new("backticks")
|
|
|
|
.long("backticks")
|
2021-11-18 16:17:15 +00:00
|
|
|
.help("For more information see `echo test`"),
|
2021-10-06 23:33:06 +00:00
|
|
|
)
|
2021-11-18 16:17:15 +00:00
|
|
|
.arg(Arg::new("backslash").long("backslash").help("Avoid '\\n'"))
|
2021-10-06 23:33:06 +00:00
|
|
|
.arg(
|
|
|
|
Arg::new("brackets")
|
|
|
|
.long("brackets")
|
2021-11-18 16:17:15 +00:00
|
|
|
.help("List packages [filter]"),
|
2021-10-06 23:33:06 +00:00
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::new("expansions")
|
|
|
|
.long("expansions")
|
2021-11-18 16:17:15 +00:00
|
|
|
.help("Execute the shell command with $SHELL"),
|
2021-10-06 23:33:06 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
static FIG_SPECIAL_HELP: &str = r#"const completion: Fig.Spec = {
|
|
|
|
name: "my_app",
|
|
|
|
description: "",
|
|
|
|
options: [
|
|
|
|
{
|
|
|
|
name: ["-h", "--help"],
|
|
|
|
description: "Print help information",
|
|
|
|
},
|
2021-10-11 15:49:55 +00:00
|
|
|
{
|
|
|
|
name: ["-V", "--version"],
|
|
|
|
description: "Print version information",
|
|
|
|
},
|
2021-10-06 23:33:06 +00:00
|
|
|
{
|
|
|
|
name: "--single-quotes",
|
|
|
|
description: "Can be 'always', 'auto', or 'never'",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "--double-quotes",
|
|
|
|
description: "Can be \"always\", \"auto\", or \"never\"",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "--backticks",
|
|
|
|
description: "For more information see `echo test`",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "--backslash",
|
|
|
|
description: "Avoid '\\n'",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "--brackets",
|
|
|
|
description: "List packages [filter]",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "--expansions",
|
|
|
|
description: "Execute the shell command with $SHELL",
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
|
|
|
|
export default completion;
|
|
|
|
"#;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn fig_with_aliases() {
|
|
|
|
let mut app = build_app_with_aliases();
|
2021-10-12 12:57:26 +00:00
|
|
|
common(Fig, &mut app, "cmd", FIG_ALIASES);
|
2021-10-06 23:33:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn build_app_with_aliases() -> App<'static> {
|
|
|
|
App::new("cmd")
|
2021-10-11 15:49:55 +00:00
|
|
|
.version("3.0")
|
2021-10-06 23:33:06 +00:00
|
|
|
.about("testing bash completions")
|
|
|
|
.arg(
|
|
|
|
Arg::new("flag")
|
|
|
|
.short('f')
|
|
|
|
.visible_short_alias('F')
|
|
|
|
.long("flag")
|
|
|
|
.visible_alias("flg")
|
2021-11-18 16:17:15 +00:00
|
|
|
.help("cmd flag"),
|
2021-10-06 23:33:06 +00:00
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::new("option")
|
|
|
|
.short('o')
|
|
|
|
.visible_short_alias('O')
|
|
|
|
.long("option")
|
|
|
|
.visible_alias("opt")
|
2021-11-18 16:17:15 +00:00
|
|
|
.help("cmd option")
|
2021-10-06 23:33:06 +00:00
|
|
|
.takes_value(true),
|
|
|
|
)
|
|
|
|
.arg(Arg::new("positional"))
|
|
|
|
}
|
|
|
|
|
|
|
|
static FIG_ALIASES: &str = r#"const completion: Fig.Spec = {
|
|
|
|
name: "cmd",
|
|
|
|
description: "testing bash completions",
|
|
|
|
options: [
|
|
|
|
{
|
|
|
|
name: ["-o", "-O", "--option", "--opt"],
|
|
|
|
description: "cmd option",
|
|
|
|
args: {
|
|
|
|
name: "option",
|
|
|
|
isOptional: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: ["-h", "--help"],
|
|
|
|
description: "Print help information",
|
|
|
|
},
|
2021-10-11 15:49:55 +00:00
|
|
|
{
|
|
|
|
name: ["-V", "--version"],
|
|
|
|
description: "Print version information",
|
|
|
|
},
|
2021-10-06 23:33:06 +00:00
|
|
|
{
|
|
|
|
name: ["-f", "-F", "--flag", "--flg"],
|
|
|
|
description: "cmd flag",
|
|
|
|
},
|
|
|
|
],
|
|
|
|
args: {
|
|
|
|
name: "positional",
|
|
|
|
isOptional: true,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
export default completion;
|
|
|
|
"#;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn fig_with_sub_subcommands() {
|
|
|
|
let mut app = build_app_sub_subcommands();
|
2021-10-12 12:57:26 +00:00
|
|
|
common(Fig, &mut app, "my_app", FIG_SUB_SUBCMDS);
|
2021-10-06 23:33:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn build_app_sub_subcommands() -> App<'static> {
|
|
|
|
build_app_with_name("my_app").subcommand(
|
|
|
|
App::new("some_cmd")
|
|
|
|
.about("top level subcommand")
|
|
|
|
.subcommand(
|
|
|
|
App::new("sub_cmd").about("sub-subcommand").arg(
|
|
|
|
Arg::new("config")
|
|
|
|
.long("--config")
|
|
|
|
.takes_value(true)
|
2021-11-18 16:17:15 +00:00
|
|
|
.help("the other case to test"),
|
2021-10-06 23:33:06 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
static FIG_SUB_SUBCMDS: &str = r#"const completion: Fig.Spec = {
|
|
|
|
name: "my_app",
|
|
|
|
description: "Tests completions",
|
|
|
|
subcommands: [
|
|
|
|
{
|
|
|
|
name: "test",
|
|
|
|
description: "tests things",
|
|
|
|
options: [
|
|
|
|
{
|
|
|
|
name: "--case",
|
|
|
|
description: "the case to test",
|
|
|
|
args: {
|
|
|
|
name: "case",
|
|
|
|
isOptional: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2021-10-12 14:08:22 +00:00
|
|
|
name: ["-h", "--help"],
|
|
|
|
description: "Print help information",
|
2021-10-06 23:33:06 +00:00
|
|
|
},
|
2021-10-11 15:49:55 +00:00
|
|
|
{
|
|
|
|
name: ["-V", "--version"],
|
|
|
|
description: "Print version information",
|
|
|
|
},
|
2021-10-06 23:33:06 +00:00
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "some_cmd",
|
|
|
|
description: "top level subcommand",
|
|
|
|
subcommands: [
|
|
|
|
{
|
|
|
|
name: "sub_cmd",
|
|
|
|
description: "sub-subcommand",
|
|
|
|
options: [
|
|
|
|
{
|
|
|
|
name: "--config",
|
|
|
|
description: "the other case to test",
|
|
|
|
args: {
|
|
|
|
name: "config",
|
|
|
|
isOptional: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2021-10-12 18:59:56 +00:00
|
|
|
name: ["-h", "--help"],
|
|
|
|
description: "Print help information",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: ["-V", "--version"],
|
|
|
|
description: "Print version information",
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "help",
|
|
|
|
description: "Print this message or the help of the given subcommand(s)",
|
|
|
|
options: [
|
|
|
|
{
|
|
|
|
name: ["-h", "--help"],
|
2021-10-06 23:33:06 +00:00
|
|
|
description: "Print help information",
|
|
|
|
},
|
|
|
|
{
|
2021-10-12 18:59:56 +00:00
|
|
|
name: ["-V", "--version"],
|
2021-10-06 23:33:06 +00:00
|
|
|
description: "Print version information",
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
options: [
|
|
|
|
{
|
2021-10-12 14:08:22 +00:00
|
|
|
name: ["-h", "--help"],
|
|
|
|
description: "Print help information",
|
2021-10-06 23:33:06 +00:00
|
|
|
},
|
2021-10-11 15:49:55 +00:00
|
|
|
{
|
|
|
|
name: ["-V", "--version"],
|
|
|
|
description: "Print version information",
|
|
|
|
},
|
2021-10-06 23:33:06 +00:00
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "help",
|
|
|
|
description: "Print this message or the help of the given subcommand(s)",
|
|
|
|
options: [
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
options: [
|
|
|
|
{
|
|
|
|
name: ["-h", "--help"],
|
|
|
|
description: "Print help information",
|
|
|
|
},
|
2021-10-11 15:49:55 +00:00
|
|
|
{
|
|
|
|
name: ["-V", "--version"],
|
|
|
|
description: "Print version information",
|
|
|
|
},
|
2021-10-06 23:33:06 +00:00
|
|
|
],
|
|
|
|
args: {
|
|
|
|
name: "file",
|
|
|
|
isOptional: true,
|
|
|
|
template: "filepaths",
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
export default completion;
|
|
|
|
"#;
|