Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(complete): Skeleton for Rust-driven completions #3656

Merged
merged 23 commits into from
Apr 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
89c2b3b
docs(complete): Clarify examples
epage Apr 27, 2022
3d64eba
test(complete): Option to verify examples
epage Apr 27, 2022
f083ef9
fix(lex)!: Don't do prefix matching by default
epage Apr 27, 2022
d4ddc5f
clap(debug): More conflict details
epage Apr 27, 2022
bbf6488
fix(complete): Send debug statements to stderr
epage Apr 27, 2022
9f9e410
feat(complete): Minimal rust-completion
epage Apr 15, 2022
5882e3d
feat(complete): Basic subcommand support
epage Apr 27, 2022
018b8bd
feat(complete): Complete possible values
epage Apr 27, 2022
2d70927
fix(complete): Detect which argument is being completed
epage Apr 27, 2022
4444350
feat(complete): Only list for current positional
epage Apr 27, 2022
458b4ae
feat(complete): Escaped args are always positional
epage Apr 27, 2022
0112ad8
refactor(complete): Extract arg value completion
epage Apr 27, 2022
63e0fd5
fix(complete): Don't count flags as positionals
epage Apr 27, 2022
a574f22
feat(complete): Look up partial matches
epage Apr 27, 2022
fe70fbc
fix(complete): Only use IFS between items
epage Apr 27, 2022
2701f48
fix(complete): Don't require IFS
epage Apr 27, 2022
6895806
fix(complete: Use correct value name for IFS
epage Apr 27, 2022
f489284
fix(complete): Allow subcommands in escaped arguments
epage Apr 27, 2022
ca4439a
fix(complete): Make short flags additive
epage Apr 27, 2022
c9b6d62
test(complete): Cover subcommands
epage Apr 27, 2022
4b9dd3f
test(complete): Cover long flags
epage Apr 27, 2022
53ae382
feat(complete): Add debug aids
epage Apr 27, 2022
1922b89
fix(complete): Correctly detect positionals
epage Apr 27, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

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