diff --git a/clap_complete/examples/dynamic.rs b/clap_complete/examples/dynamic.rs index f22b7ada..ba61f5fd 100644 --- a/clap_complete/examples/dynamic.rs +++ b/clap_complete/examples/dynamic.rs @@ -16,15 +16,15 @@ fn command() -> clap::Command { .value_parser(["json", "yaml", "toml"]), ) .args_conflicts_with_subcommands(true); - clap_complete::dynamic::CompleteCommand::augment_subcommands(cmd) + clap_complete::CompleteCommand::augment_subcommands(cmd) } fn main() { - clap_complete::dynamic::CompleteEnv::with_factory(command).complete(); + clap_complete::CompleteEnv::with_factory(command).complete(); let cmd = command(); let matches = cmd.get_matches(); - if let Ok(completions) = clap_complete::dynamic::CompleteCommand::from_arg_matches(&matches) { + if let Ok(completions) = clap_complete::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 1f63cadb..83050bdd 100644 --- a/clap_complete/examples/exhaustive.rs +++ b/clap_complete/examples/exhaustive.rs @@ -5,7 +5,7 @@ use clap_complete::{generate, Generator, Shell}; fn main() { #[cfg(feature = "unstable-dynamic")] - clap_complete::dynamic::CompleteEnv::with_factory(cli).complete(); + clap_complete::CompleteEnv::with_factory(cli).complete(); let matches = cli().get_matches(); if let Some(generator) = matches.get_one::("generate") { @@ -16,7 +16,7 @@ fn main() { } #[cfg(feature = "unstable-command")] - if let Ok(completions) = clap_complete::dynamic::CompleteCommand::from_arg_matches(&matches) { + if let Ok(completions) = clap_complete::CompleteCommand::from_arg_matches(&matches) { completions.complete(&mut cli()); return; }; @@ -199,6 +199,6 @@ fn cli() -> clap::Command { ]), ]); #[cfg(feature = "unstable-command")] - let cli = clap_complete::dynamic::CompleteCommand::augment_subcommands(cli); + let cli = clap_complete::CompleteCommand::augment_subcommands(cli); cli } diff --git a/clap_complete/src/dynamic/command/mod.rs b/clap_complete/src/command/mod.rs similarity index 98% rename from clap_complete/src/dynamic/command/mod.rs rename to clap_complete/src/command/mod.rs index ce3c4ffd..7274468f 100644 --- a/clap_complete/src/dynamic/command/mod.rs +++ b/clap_complete/src/command/mod.rs @@ -55,7 +55,7 @@ pub use shells::*; /// ```no_run /// // src/main.rs /// use clap::{CommandFactory, FromArgMatches, Parser, Subcommand}; -/// use clap_complete::dynamic::CompleteCommand; +/// use clap_complete::CompleteCommand; /// /// #[derive(Parser, Debug)] /// #[clap(name = "dynamic", about = "A dynamic command line tool")] @@ -122,7 +122,7 @@ impl CompleteCommand { /// ```no_run /// // src/main.rs /// use clap::{CommandFactory, FromArgMatches, Parser, Subcommand}; -/// use clap_complete::dynamic::CompleteArgs; +/// use clap_complete::CompleteArgs; /// /// #[derive(Parser, Debug)] /// #[clap(name = "dynamic", about = "A dynamic command line tool")] diff --git a/clap_complete/src/dynamic/command/shells.rs b/clap_complete/src/command/shells.rs similarity index 100% rename from clap_complete/src/dynamic/command/shells.rs rename to clap_complete/src/command/shells.rs diff --git a/clap_complete/src/dynamic/mod.rs b/clap_complete/src/dynamic/mod.rs index 118b7a26..46379cc7 100644 --- a/clap_complete/src/dynamic/mod.rs +++ b/clap_complete/src/dynamic/mod.rs @@ -9,17 +9,7 @@ mod candidate; mod complete; mod custom; -#[cfg(feature = "unstable-command")] -pub mod command; -pub mod env; - pub use candidate::CompletionCandidate; pub use complete::complete; pub use custom::ArgValueCompleter; pub use custom::CustomCompleter; - -#[cfg(feature = "unstable-command")] -pub use command::CompleteArgs; -#[cfg(feature = "unstable-command")] -pub use command::CompleteCommand; -pub use env::CompleteEnv; diff --git a/clap_complete/src/dynamic/env/mod.rs b/clap_complete/src/env/mod.rs similarity index 97% rename from clap_complete/src/dynamic/env/mod.rs rename to clap_complete/src/env/mod.rs index f46af829..2bd2a0a7 100644 --- a/clap_complete/src/dynamic/env/mod.rs +++ b/clap_complete/src/env/mod.rs @@ -2,7 +2,7 @@ //! //! See [`CompleteEnv`]: //! ```rust -//! # use clap_complete::dynamic::CompleteEnv; +//! # use clap_complete::CompleteEnv; //! fn cli() -> clap::Command { //! // ... //! # clap::Command::new("empty") @@ -64,7 +64,7 @@ pub use shells::*; /// - Flexibility: there is no concern over it interfering with other CLI logic /// /// ```rust -/// # use clap_complete::dynamic::CompleteEnv; +/// # use clap_complete::CompleteEnv; /// fn cli() -> clap::Command { /// // ... /// # clap::Command::new("empty") @@ -90,7 +90,7 @@ impl<'s, F: FnOnce() -> clap::Command> CompleteEnv<'s, F> { /// /// Builder: /// ```rust - /// # use clap_complete::dynamic::CompleteEnv; + /// # use clap_complete::CompleteEnv; /// fn cli() -> clap::Command { /// // ... /// # clap::Command::new("empty") @@ -107,7 +107,7 @@ impl<'s, F: FnOnce() -> clap::Command> CompleteEnv<'s, F> { /// Derive: /// ``` /// # use clap::Parser; - /// # use clap_complete::dynamic::CompleteEnv; + /// # use clap_complete::CompleteEnv; /// use clap::CommandFactory as _; /// /// #[derive(Debug, Parser)] diff --git a/clap_complete/src/dynamic/env/shells.rs b/clap_complete/src/env/shells.rs similarity index 100% rename from clap_complete/src/dynamic/env/shells.rs rename to clap_complete/src/env/shells.rs diff --git a/clap_complete/src/lib.rs b/clap_complete/src/lib.rs index 3c8a1cdd..24753283 100644 --- a/clap_complete/src/lib.rs +++ b/clap_complete/src/lib.rs @@ -66,8 +66,26 @@ const INTERNAL_ERROR_MSG: &str = "Fatal internal error. Please consider filing a mod macros; pub mod aot; +#[cfg(feature = "unstable-command")] +pub mod command; #[cfg(feature = "unstable-dynamic")] pub mod dynamic; +#[cfg(feature = "unstable-dynamic")] +pub mod env; + +pub use clap::ValueHint; +#[cfg(feature = "unstable-command")] +pub use command::CompleteArgs; +#[cfg(feature = "unstable-command")] +pub use command::CompleteCommand; +#[doc(inline)] +#[cfg(feature = "unstable-dynamic")] +pub use dynamic::ArgValueCompleter; +#[doc(inline)] +#[cfg(feature = "unstable-dynamic")] +pub use dynamic::CompletionCandidate; +#[cfg(feature = "unstable-dynamic")] +pub use env::CompleteEnv; /// Deprecated, see [`aot`] pub mod generator { @@ -93,4 +111,3 @@ pub use aot::generate_to; pub use aot::Generator; /// Deprecated, see [`aot::Shell`] pub use aot::Shell; -pub use clap::ValueHint; diff --git a/clap_complete/tests/testsuite/bash.rs b/clap_complete/tests/testsuite/bash.rs index 91001a75..00c57c8f 100644 --- a/clap_complete/tests/testsuite/bash.rs +++ b/clap_complete/tests/testsuite/bash.rs @@ -114,14 +114,14 @@ fn value_terminator() { #[cfg(feature = "unstable-command")] #[test] fn register_minimal() { - use clap_complete::dynamic::command::CommandCompleter as _; + use clap_complete::command::CommandCompleter as _; let name = "my-app"; let bin = name; let completer = name; let mut buf = Vec::new(); - clap_complete::dynamic::command::Bash + clap_complete::command::Bash .write_registration(name, bin, completer, &mut buf) .unwrap(); snapbox::Assert::new()