clap_complete/lib.rs
1// Copyright ⓒ 2015-2018 Kevin B. Knapp
2//
3// `clap_complete` is distributed under the terms of both the MIT license and the Apache License
4// (Version 2.0).
5// See the [LICENSE-APACHE](LICENSE-APACHE) and [LICENSE-MIT](LICENSE-MIT) files in this repository
6// for more information.
7
8//! ## Quick Start
9//!
10//! - For generating at compile-time, see [`generate_to`]
11//! - For generating at runtime, see [`generate`]
12//!
13//! [`Shell`] is a convenience `enum` for an argument value type that implements `Generator`
14//! for each natively-supported shell type.
15//!
16//! ## Example
17//!
18//! ```rust,no_run
19//! use clap::{Command, Arg, ValueHint, value_parser, ArgAction};
20//! use clap_complete::aot::{generate, Generator, Shell};
21//! use std::io;
22//!
23//! fn build_cli() -> Command {
24//! Command::new("example")
25//! .arg(Arg::new("file")
26//! .help("some input file")
27//! .value_hint(ValueHint::AnyPath))
28//! .arg(Arg::new("generator")
29//! .long("generate")
30//! .action(ArgAction::Set)
31//! .value_parser(value_parser!(Shell)))
32//! }
33//!
34//! fn print_completions<G: Generator>(generator: G, cmd: &mut Command) {
35//! generate(generator, cmd, cmd.get_name().to_string(), &mut io::stdout());
36//! }
37//!
38//! fn main() {
39//! let matches = build_cli().get_matches();
40//!
41//! if let Some(generator) = matches.get_one::<Shell>("generator").copied() {
42//! let mut cmd = build_cli();
43//! eprintln!("Generating completion file for {generator}...");
44//! print_completions(generator, &mut cmd);
45//! }
46//! }
47//! ```
48
49#![doc(html_logo_url = "https://raw.githubusercontent.com/clap-rs/clap/master/assets/clap.png")]
50#![doc = include_str!("../README.md")]
51#![cfg_attr(docsrs, feature(doc_auto_cfg))]
52#![forbid(unsafe_code)]
53#![warn(missing_docs)]
54#![allow(clippy::needless_doctest_main)]
55#![warn(clippy::print_stderr)]
56#![warn(clippy::print_stdout)]
57
58const INTERNAL_ERROR_MSG: &str = "Fatal internal error. Please consider filing a bug \
59 report at https://github.com/clap-rs/clap/issues";
60
61#[macro_use]
62#[allow(missing_docs)]
63mod macros;
64
65pub mod aot;
66#[cfg(feature = "unstable-dynamic")]
67pub mod engine;
68#[cfg(feature = "unstable-dynamic")]
69pub mod env;
70
71pub use clap::ValueHint;
72#[doc(inline)]
73#[cfg(feature = "unstable-dynamic")]
74pub use engine::ArgValueCandidates;
75#[cfg(feature = "unstable-dynamic")]
76pub use engine::ArgValueCompleter;
77#[doc(inline)]
78#[cfg(feature = "unstable-dynamic")]
79pub use engine::CompletionCandidate;
80#[cfg(feature = "unstable-dynamic")]
81pub use engine::PathCompleter;
82#[cfg(feature = "unstable-dynamic")]
83pub use env::CompleteEnv;
84
85/// Deprecated, see [`aot`]
86pub mod generator {
87 pub use crate::aot::generate;
88 pub use crate::aot::generate_to;
89 pub use crate::aot::utils;
90 pub use crate::aot::Generator;
91}
92/// Deprecated, see [`aot`]
93pub mod shells {
94 pub use crate::aot::Bash;
95 pub use crate::aot::Elvish;
96 pub use crate::aot::Fish;
97 pub use crate::aot::PowerShell;
98 pub use crate::aot::Shell;
99 pub use crate::aot::Zsh;
100}
101/// Deprecated, see [`aot::generate`]
102pub use aot::generate;
103/// Deprecated, see [`aot::generate_to`]
104pub use aot::generate_to;
105/// Deprecated, see [`aot::Generator`]
106pub use aot::Generator;
107/// Deprecated, see [`aot::Shell`]
108pub use aot::Shell;