diff --git a/clap_complete/src/generator/mod.rs b/clap_complete/src/aot/generator/mod.rs similarity index 100% rename from clap_complete/src/generator/mod.rs rename to clap_complete/src/aot/generator/mod.rs diff --git a/clap_complete/src/generator/utils.rs b/clap_complete/src/aot/generator/utils.rs similarity index 100% rename from clap_complete/src/generator/utils.rs rename to clap_complete/src/aot/generator/utils.rs diff --git a/clap_complete/src/aot/mod.rs b/clap_complete/src/aot/mod.rs new file mode 100644 index 00000000000..bd25ca0e51f --- /dev/null +++ b/clap_complete/src/aot/mod.rs @@ -0,0 +1,52 @@ +//! Prebuilt completions +//! +//! ## Quick Start +//! +//! - For generating at compile-time, see [`generate_to`] +//! - For generating at runtime, see [`generate`] +//! +//! [`Shell`] is a convenience `enum` for an argument value type that implements `Generator` +//! for each natively-supported shell type. +//! +//! ## Example +//! +//! ```rust,no_run +//! use clap::{Command, Arg, ValueHint, value_parser, ArgAction}; +//! use clap_complete::{generate, Generator, Shell}; +//! use std::io; +//! +//! fn build_cli() -> Command { +//! Command::new("example") +//! .arg(Arg::new("file") +//! .help("some input file") +//! .value_hint(ValueHint::AnyPath), +//! ) +//! .arg( +//! Arg::new("generator") +//! .long("generate") +//! .action(ArgAction::Set) +//! .value_parser(value_parser!(Shell)), +//! ) +//! } +//! +//! fn print_completions(gen: G, cmd: &mut Command) { +//! generate(gen, cmd, cmd.get_name().to_string(), &mut io::stdout()); +//! } +//! +//! fn main() { +//! let matches = build_cli().get_matches(); +//! +//! if let Some(generator) = matches.get_one::("generator").copied() { +//! let mut cmd = build_cli(); +//! eprintln!("Generating completion file for {generator}..."); +//! print_completions(generator, &mut cmd); +//! } +//! } +//! ``` + +mod generator; +mod shells; + +pub use clap::ValueHint; +pub use generator::*; +pub use shells::*; diff --git a/clap_complete/src/shells/bash.rs b/clap_complete/src/aot/shells/bash.rs similarity index 100% rename from clap_complete/src/shells/bash.rs rename to clap_complete/src/aot/shells/bash.rs diff --git a/clap_complete/src/shells/elvish.rs b/clap_complete/src/aot/shells/elvish.rs similarity index 100% rename from clap_complete/src/shells/elvish.rs rename to clap_complete/src/aot/shells/elvish.rs diff --git a/clap_complete/src/shells/fish.rs b/clap_complete/src/aot/shells/fish.rs similarity index 100% rename from clap_complete/src/shells/fish.rs rename to clap_complete/src/aot/shells/fish.rs diff --git a/clap_complete/src/shells/mod.rs b/clap_complete/src/aot/shells/mod.rs similarity index 100% rename from clap_complete/src/shells/mod.rs rename to clap_complete/src/aot/shells/mod.rs diff --git a/clap_complete/src/shells/powershell.rs b/clap_complete/src/aot/shells/powershell.rs similarity index 100% rename from clap_complete/src/shells/powershell.rs rename to clap_complete/src/aot/shells/powershell.rs diff --git a/clap_complete/src/shells/shell.rs b/clap_complete/src/aot/shells/shell.rs similarity index 100% rename from clap_complete/src/shells/shell.rs rename to clap_complete/src/aot/shells/shell.rs diff --git a/clap_complete/src/shells/zsh.rs b/clap_complete/src/aot/shells/zsh.rs similarity index 99% rename from clap_complete/src/shells/zsh.rs rename to clap_complete/src/aot/shells/zsh.rs index 6b0e2dc1680..364df24f185 100644 --- a/clap_complete/src/shells/zsh.rs +++ b/clap_complete/src/aot/shells/zsh.rs @@ -671,7 +671,7 @@ fn write_positionals_of(p: &Command) -> String { #[cfg(test)] mod tests { - use crate::shells::zsh::{escape_help, escape_value}; + use super::{escape_help, escape_value}; #[test] fn test_escape_value() { diff --git a/clap_complete/src/lib.rs b/clap_complete/src/lib.rs index c97a9f1a728..3c8a1cddfca 100644 --- a/clap_complete/src/lib.rs +++ b/clap_complete/src/lib.rs @@ -17,7 +17,7 @@ //! //! ```rust,no_run //! use clap::{Command, Arg, ValueHint, value_parser, ArgAction}; -//! use clap_complete::{generate, Generator, Shell}; +//! use clap_complete::aot::{generate, Generator, Shell}; //! use std::io; //! //! fn build_cli() -> Command { @@ -65,14 +65,32 @@ const INTERNAL_ERROR_MSG: &str = "Fatal internal error. Please consider filing a #[allow(missing_docs)] mod macros; -pub mod generator; -pub mod shells; - -pub use clap::ValueHint; -pub use generator::generate; -pub use generator::generate_to; -pub use generator::Generator; -pub use shells::Shell; - +pub mod aot; #[cfg(feature = "unstable-dynamic")] pub mod dynamic; + +/// Deprecated, see [`aot`] +pub mod generator { + pub use crate::aot::generate; + pub use crate::aot::generate_to; + pub use crate::aot::utils; + pub use crate::aot::Generator; +} +/// Deprecated, see [`aot`] +pub mod shells { + pub use crate::aot::Bash; + pub use crate::aot::Elvish; + pub use crate::aot::Fish; + pub use crate::aot::PowerShell; + pub use crate::aot::Shell; + pub use crate::aot::Zsh; +} +/// Deprecated, see [`aot::generate`] +pub use aot::generate; +/// Deprecated, see [`aot::generate_to`] +pub use aot::generate_to; +/// Deprecated, see [`aot::Generator`] +pub use aot::Generator; +/// Deprecated, see [`aot::Shell`] +pub use aot::Shell; +pub use clap::ValueHint;