Skip to content

Commit 6727c15

Browse files
committed
fix(complete): Section off existing completions
1 parent 6842ed9 commit 6727c15

File tree

11 files changed

+81
-11
lines changed

11 files changed

+81
-11
lines changed

clap_complete/src/aot/mod.rs

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
//! Prebuilt completions
2+
//!
3+
//! ## Quick Start
4+
//!
5+
//! - For generating at compile-time, see [`generate_to`]
6+
//! - For generating at runtime, see [`generate`]
7+
//!
8+
//! [`Shell`] is a convenience `enum` for an argument value type that implements `Generator`
9+
//! for each natively-supported shell type.
10+
//!
11+
//! ## Example
12+
//!
13+
//! ```rust,no_run
14+
//! use clap::{Command, Arg, ValueHint, value_parser, ArgAction};
15+
//! use clap_complete::{generate, Generator, Shell};
16+
//! use std::io;
17+
//!
18+
//! fn build_cli() -> Command {
19+
//! Command::new("example")
20+
//! .arg(Arg::new("file")
21+
//! .help("some input file")
22+
//! .value_hint(ValueHint::AnyPath),
23+
//! )
24+
//! .arg(
25+
//! Arg::new("generator")
26+
//! .long("generate")
27+
//! .action(ArgAction::Set)
28+
//! .value_parser(value_parser!(Shell)),
29+
//! )
30+
//! }
31+
//!
32+
//! fn print_completions<G: Generator>(gen: G, cmd: &mut Command) {
33+
//! generate(gen, cmd, cmd.get_name().to_string(), &mut io::stdout());
34+
//! }
35+
//!
36+
//! fn main() {
37+
//! let matches = build_cli().get_matches();
38+
//!
39+
//! if let Some(generator) = matches.get_one::<Shell>("generator").copied() {
40+
//! let mut cmd = build_cli();
41+
//! eprintln!("Generating completion file for {generator}...");
42+
//! print_completions(generator, &mut cmd);
43+
//! }
44+
//! }
45+
//! ```
46+
47+
mod generator;
48+
mod shells;
49+
50+
pub use clap::ValueHint;
51+
pub use generator::*;
52+
pub use shells::*;
File renamed without changes.

clap_complete/src/shells/zsh.rs renamed to clap_complete/src/aot/shells/zsh.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ fn write_positionals_of(p: &Command) -> String {
671671

672672
#[cfg(test)]
673673
mod tests {
674-
use crate::shells::zsh::{escape_help, escape_value};
674+
use super::{escape_help, escape_value};
675675

676676
#[test]
677677
fn test_escape_value() {

clap_complete/src/lib.rs

+28-10
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
//!
1818
//! ```rust,no_run
1919
//! use clap::{Command, Arg, ValueHint, value_parser, ArgAction};
20-
//! use clap_complete::{generate, Generator, Shell};
20+
//! use clap_complete::aot::{generate, Generator, Shell};
2121
//! use std::io;
2222
//!
2323
//! fn build_cli() -> Command {
@@ -65,14 +65,32 @@ const INTERNAL_ERROR_MSG: &str = "Fatal internal error. Please consider filing a
6565
#[allow(missing_docs)]
6666
mod macros;
6767

68-
pub mod generator;
69-
pub mod shells;
70-
71-
pub use clap::ValueHint;
72-
pub use generator::generate;
73-
pub use generator::generate_to;
74-
pub use generator::Generator;
75-
pub use shells::Shell;
76-
68+
pub mod aot;
7769
#[cfg(feature = "unstable-dynamic")]
7870
pub mod dynamic;
71+
72+
/// Deprecated, see [`aot`]
73+
pub mod generator {
74+
pub use crate::aot::generate;
75+
pub use crate::aot::generate_to;
76+
pub use crate::aot::utils;
77+
pub use crate::aot::Generator;
78+
}
79+
/// Deprecated, see [`aot`]
80+
pub mod shells {
81+
pub use crate::aot::Bash;
82+
pub use crate::aot::Elvish;
83+
pub use crate::aot::Fish;
84+
pub use crate::aot::PowerShell;
85+
pub use crate::aot::Shell;
86+
pub use crate::aot::Zsh;
87+
}
88+
/// Deprecated, see [`aot::generate`]
89+
pub use aot::generate;
90+
/// Deprecated, see [`aot::generate_to`]
91+
pub use aot::generate_to;
92+
/// Deprecated, see [`aot::Generator`]
93+
pub use aot::Generator;
94+
/// Deprecated, see [`aot::Shell`]
95+
pub use aot::Shell;
96+
pub use clap::ValueHint;

0 commit comments

Comments
 (0)