Skip to content

Commit

Permalink
Merge pull request #3656 from epage/complete
Browse files Browse the repository at this point in the history
feat(complete): Skeleton for Rust-driven completions
  • Loading branch information
epage authored Apr 27, 2022
2 parents 406bfbd + 1922b89 commit 9bf01e9
Show file tree
Hide file tree
Showing 19 changed files with 855 additions and 78 deletions.
13 changes: 13 additions & 0 deletions clap_complete/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,27 @@ bench = false

[dependencies]
clap = { path = "../", version = "3.1.10", default-features = false, features = ["std"] }
clap_lex = { path = "../clap_lex", version = "0.1.0", optional = true }
is_executable = { version = "1.0.1", optional = true }
os_str_bytes = { version = "6.0", default-features = false, features = ["raw_os_str"], optional = true }
pathdiff = { version = "0.2.1", optional = true }
shlex = { version = "1.1.0", optional = true }
unicode-xid = { version = "0.2.2", optional = true }

[dev-dependencies]
pretty_assertions = "1.0"
snapbox = { version = "0.2", features = ["diff"] }
# Cutting out `filesystem` feature
trycmd = { version = "0.13", default-features = false, features = ["color-auto", "diff", "examples"] }
clap = { path = "../", version = "3.1.10", default-features = false, features = ["std", "derive"] }

[[example]]
name = "dynamic"
required-features = ["unstable-dynamic"]

[features]
default = []
unstable-dynamic = ["clap_lex", "shlex", "unicode-xid", "os_str_bytes", "clap/derive", "is_executable", "pathdiff"]
debug = ["clap/debug"]

[package.metadata.docs.rs]
Expand Down
11 changes: 0 additions & 11 deletions clap_complete/examples/bash_completion.rs

This file was deleted.

File renamed without changes.
File renamed without changes.
39 changes: 39 additions & 0 deletions clap_complete/examples/dynamic.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
use clap::FromArgMatches;
use clap::Subcommand;

fn command() -> clap::Command<'static> {
let cmd = clap::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')
.possible_values(["json", "yaml", "toml"]),
)
.args_conflicts_with_subcommands(true);
let cmd = clap_complete::dynamic::bash::CompleteCommand::augment_subcommands(cmd);
cmd
}

fn main() {
let cmd = command();
let matches = cmd.get_matches();
if let Ok(completions) =
clap_complete::dynamic::bash::CompleteCommand::from_arg_matches(&matches)
{
completions.complete(&mut command());
} else {
println!("{:#?}", matches);
}
}

#[test]
fn verify_cli() {
use clap::CommandFactory;
command().command().debug_assert();
}
Loading

0 comments on commit 9bf01e9

Please sign in to comment.