From b4625620fdb9a4d8562043e4848b8b2f6fe19471 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Fri, 9 Aug 2024 15:09:40 -0500 Subject: [PATCH 1/4] fix(complete): Make it easier to access clap integration --- clap_complete/src/dynamic/mod.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/clap_complete/src/dynamic/mod.rs b/clap_complete/src/dynamic/mod.rs index 0809c04eb9b..d7c7ce495aa 100644 --- a/clap_complete/src/dynamic/mod.rs +++ b/clap_complete/src/dynamic/mod.rs @@ -12,3 +12,7 @@ pub use candidate::CompletionCandidate; pub use complete::complete; pub use custom::ArgValueCompleter; pub use custom::CustomCompleter; + +// These live in `shells` because they are tightly coupled with the `ShellCompleter`s +pub use shells::CompleteArgs; +pub use shells::CompleteCommand; From 5f322e481a05aa3431f3c0c720d141dc677204b1 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Fri, 9 Aug 2024 15:11:55 -0500 Subject: [PATCH 2/4] docs(complete): Tell users how to customize --- clap_complete/src/dynamic/mod.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/clap_complete/src/dynamic/mod.rs b/clap_complete/src/dynamic/mod.rs index d7c7ce495aa..76ced9088e6 100644 --- a/clap_complete/src/dynamic/mod.rs +++ b/clap_complete/src/dynamic/mod.rs @@ -1,6 +1,11 @@ //! Complete commands within shells //! //! For quick-start, see [`shells::CompleteCommand`] +//! +//! To customize completions, see +//! - [`ValueHint`][crate::ValueHint] +//! - [`ValueEnum`][clap::ValueEnum] +//! - [`ArgValueCompleter`] mod candidate; mod complete; From 6d45f41415de4f8d16e82129ce1c3bcba83a760b Mon Sep 17 00:00:00 2001 From: Ed Page Date: Fri, 9 Aug 2024 15:14:33 -0500 Subject: [PATCH 3/4] docs(complete): Clarify dynamic's support for ValueHint --- clap_builder/src/builder/value_hint.rs | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/clap_builder/src/builder/value_hint.rs b/clap_builder/src/builder/value_hint.rs index 71827fb7656..57b75cfc3fd 100644 --- a/clap_builder/src/builder/value_hint.rs +++ b/clap_builder/src/builder/value_hint.rs @@ -8,19 +8,19 @@ use std::str::FromStr; /// /// Overview of which hints are supported by which shell: /// -/// | Hint | zsh | fish[^1]| -/// | ---------------------- | --- | ------- | -/// | `AnyPath` | Yes | Yes | -/// | `FilePath` | Yes | Yes | -/// | `DirPath` | Yes | Yes | -/// | `ExecutablePath` | Yes | Partial | -/// | `CommandName` | Yes | Yes | -/// | `CommandString` | Yes | Partial | -/// | `CommandWithArguments` | Yes | | -/// | `Username` | Yes | Yes | -/// | `Hostname` | Yes | Yes | -/// | `Url` | Yes | | -/// | `EmailAddress` | Yes | | +/// | Hint | zsh | fish[^1] | dynamic | +/// | ---------------------- | --- | ---------|---------| +/// | `AnyPath` | Yes | Yes | Yes | +/// | `FilePath` | Yes | Yes | Yes | +/// | `DirPath` | Yes | Yes | Yes | +/// | `ExecutablePath` | Yes | Partial | Yes | +/// | `CommandName` | Yes | Yes | No | +/// | `CommandString` | Yes | Partial | No | +/// | `CommandWithArguments` | Yes | | No | +/// | `Username` | Yes | Yes | No | +/// | `Hostname` | Yes | Yes | No | +/// | `Url` | Yes | | No | +/// | `EmailAddress` | Yes | | No | /// /// [^1]: fish completions currently only support named arguments (e.g. -o or --opt), not /// positional arguments. From fb243a8801c3d3c1f8726a795be7e8335965ad68 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Fri, 9 Aug 2024 15:14:33 -0500 Subject: [PATCH 4/4] doc(complete): Show easier access to CompleteCommand --- clap_complete/examples/dynamic.rs | 6 ++---- clap_complete/examples/exhaustive.rs | 6 ++---- clap_complete/src/dynamic/mod.rs | 2 +- clap_complete/src/dynamic/shells/mod.rs | 4 ++-- 4 files changed, 7 insertions(+), 11 deletions(-) diff --git a/clap_complete/examples/dynamic.rs b/clap_complete/examples/dynamic.rs index ccaf7d8ad2d..9054fcac0f5 100644 --- a/clap_complete/examples/dynamic.rs +++ b/clap_complete/examples/dynamic.rs @@ -16,15 +16,13 @@ fn command() -> clap::Command { .value_parser(["json", "yaml", "toml"]), ) .args_conflicts_with_subcommands(true); - clap_complete::dynamic::shells::CompleteCommand::augment_subcommands(cmd) + clap_complete::dynamic::CompleteCommand::augment_subcommands(cmd) } fn main() { let cmd = command(); let matches = cmd.get_matches(); - if let Ok(completions) = - clap_complete::dynamic::shells::CompleteCommand::from_arg_matches(&matches) - { + if let Ok(completions) = clap_complete::dynamic::CompleteCommand::from_arg_matches(&matches) { completions.complete(&mut command()); } else { println!("{matches:#?}"); diff --git a/clap_complete/examples/exhaustive.rs b/clap_complete/examples/exhaustive.rs index de00da622a1..7a79c1088c5 100644 --- a/clap_complete/examples/exhaustive.rs +++ b/clap_complete/examples/exhaustive.rs @@ -13,9 +13,7 @@ fn main() { } #[cfg(feature = "unstable-dynamic")] - if let Ok(completions) = - clap_complete::dynamic::shells::CompleteCommand::from_arg_matches(&matches) - { + if let Ok(completions) = clap_complete::dynamic::CompleteCommand::from_arg_matches(&matches) { completions.complete(&mut cli()); return; }; @@ -198,6 +196,6 @@ fn cli() -> clap::Command { ]), ]); #[cfg(feature = "unstable-dynamic")] - let cli = clap_complete::dynamic::shells::CompleteCommand::augment_subcommands(cli); + let cli = clap_complete::dynamic::CompleteCommand::augment_subcommands(cli); cli } diff --git a/clap_complete/src/dynamic/mod.rs b/clap_complete/src/dynamic/mod.rs index 76ced9088e6..ef396d8d373 100644 --- a/clap_complete/src/dynamic/mod.rs +++ b/clap_complete/src/dynamic/mod.rs @@ -1,6 +1,6 @@ //! Complete commands within shells //! -//! For quick-start, see [`shells::CompleteCommand`] +//! For quick-start, see [`CompleteCommand`] //! //! To customize completions, see //! - [`ValueHint`][crate::ValueHint] diff --git a/clap_complete/src/dynamic/shells/mod.rs b/clap_complete/src/dynamic/shells/mod.rs index b8cc61c6e2b..8460a44ab11 100644 --- a/clap_complete/src/dynamic/shells/mod.rs +++ b/clap_complete/src/dynamic/shells/mod.rs @@ -30,7 +30,7 @@ use std::io::Write as _; /// ```no_run /// // src/main.rs /// use clap::{CommandFactory, FromArgMatches, Parser, Subcommand}; -/// use clap_complete::dynamic::shells::CompleteCommand; +/// use clap_complete::dynamic::CompleteCommand; /// /// #[derive(Parser, Debug)] /// #[clap(name = "dynamic", about = "A dynamic command line tool")] @@ -127,7 +127,7 @@ impl CompleteCommand { /// ```no_run /// // src/main.rs /// use clap::{CommandFactory, FromArgMatches, Parser, Subcommand}; -/// use clap_complete::dynamic::shells::CompleteArgs; +/// use clap_complete::dynamic::CompleteArgs; /// /// #[derive(Parser, Debug)] /// #[clap(name = "dynamic", about = "A dynamic command line tool")]