Skip to content

Commit

Permalink
fix(complete)!: Remove CompleteCommand
Browse files Browse the repository at this point in the history
This just has too many caveats to be worth maintaining
  • Loading branch information
epage committed Aug 29, 2024
1 parent d51922c commit 72dda07
Show file tree
Hide file tree
Showing 22 changed files with 23 additions and 1,186 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions clap_complete/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ clap = { path = "../", version = "4.5.15", default-features = false, features =
clap_lex = { path = "../clap_lex", version = "0.7.0", optional = true }
is_executable = { version = "1.0.1", optional = true }
shlex = { version = "1.3.0", optional = true }
unicode-xid = { version = "0.2.2", optional = true }

[dev-dependencies]
snapbox = { version = "0.6.0", features = ["diff", "dir", "examples"] }
Expand All @@ -51,13 +50,12 @@ automod = "1.0.14"

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

[features]
default = []
unstable-doc = ["unstable-dynamic", "unstable-command"] # for docs.rs
unstable-doc = ["unstable-dynamic"] # for docs.rs
unstable-dynamic = ["dep:clap_lex", "dep:shlex", "dep:is_executable", "clap/unstable-ext"]
unstable-command = ["unstable-dynamic", "dep:unicode-xid", "clap/derive", "dep:is_executable", "clap/unstable-ext"]
debug = ["clap/debug"]

[lints]
Expand Down
14 changes: 3 additions & 11 deletions clap_complete/examples/dynamic.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use clap::FromArgMatches;
use clap::Subcommand;

fn command() -> clap::Command {
let cmd = clap::Command::new("dynamic")
clap::Command::new("dynamic")
.arg(
clap::Arg::new("input")
.long("input")
Expand All @@ -15,20 +12,15 @@ fn command() -> clap::Command {
.short('F')
.value_parser(["json", "yaml", "toml"]),
)
.args_conflicts_with_subcommands(true);
clap_complete::CompleteCommand::augment_subcommands(cmd)
.args_conflicts_with_subcommands(true)
}

fn main() {
clap_complete::CompleteEnv::with_factory(command).complete();

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

#[test]
Expand Down
15 changes: 2 additions & 13 deletions clap_complete/examples/exhaustive.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use clap::builder::PossibleValue;
#[cfg(feature = "unstable-command")]
use clap::{FromArgMatches, Subcommand};
use clap_complete::{generate, Generator, Shell};

fn main() {
Expand All @@ -15,12 +13,6 @@ fn main() {
return;
}

#[cfg(feature = "unstable-command")]
if let Ok(completions) = clap_complete::CompleteCommand::from_arg_matches(&matches) {
completions.complete(&mut cli());
return;
};

println!("{:?}", matches);
}

Expand All @@ -30,7 +22,7 @@ fn print_completions<G: Generator>(gen: G, cmd: &mut clap::Command) {

#[allow(clippy::let_and_return)]
fn cli() -> clap::Command {
let cli = clap::Command::new("exhaustive")
clap::Command::new("exhaustive")
.version("3.0")
.propagate_version(true)
.args([
Expand Down Expand Up @@ -197,8 +189,5 @@ fn cli() -> clap::Command {
.long("email")
.value_hint(clap::ValueHint::EmailAddress),
]),
]);
#[cfg(feature = "unstable-command")]
let cli = clap_complete::CompleteCommand::augment_subcommands(cli);
cli
])
}
253 changes: 0 additions & 253 deletions clap_complete/src/command/mod.rs

This file was deleted.

Loading

0 comments on commit 72dda07

Please sign in to comment.