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//! let matches = build_cli().get_matches();
39//!
40//! if let Some(generator) = matches.get_one::<Shell>("generator").copied() {
41//! let mut cmd = build_cli();
42//! eprintln!("Generating completion file for {generator}...");
43//! print_completions(generator, &mut cmd);
44//! }
45//! ```
46
47#![doc(html_logo_url = "https://raw.githubusercontent.com/clap-rs/clap/master/assets/clap.png")]
48#![doc = include_str!("../README.md")]
49#![cfg_attr(docsrs, feature(doc_cfg))]
50#![warn(missing_docs)]
51#![allow(clippy::needless_doctest_main)]
52#![warn(clippy::print_stderr)]
53#![warn(clippy::print_stdout)]
54
55const INTERNAL_ERROR_MSG: &str = "Fatal internal error. Please consider filing a bug \
56 report at https://github.com/clap-rs/clap/issues";
57
58#[macro_use]
59#[allow(missing_docs)]
60mod macros;
61
62pub mod aot;
63#[cfg(feature = "unstable-dynamic")]
64pub mod engine;
65#[cfg(feature = "unstable-dynamic")]
66pub mod env;
67
68pub use clap::ValueHint;
69#[doc(inline)]
70#[cfg(feature = "unstable-dynamic")]
71pub use engine::ArgValueCandidates;
72#[cfg(feature = "unstable-dynamic")]
73pub use engine::ArgValueCompleter;
74#[doc(inline)]
75#[cfg(feature = "unstable-dynamic")]
76pub use engine::CompletionCandidate;
77#[cfg(feature = "unstable-dynamic")]
78pub use engine::PathCompleter;
79#[cfg(feature = "unstable-dynamic")]
80pub use env::CompleteEnv;
81
82/// Deprecated, see [`aot`]
83pub mod generator {
84 pub use crate::aot::Generator;
85 pub use crate::aot::generate;
86 pub use crate::aot::generate_to;
87 pub use crate::aot::utils;
88}
89/// Deprecated, see [`aot`]
90pub mod shells {
91 pub use crate::aot::Bash;
92 pub use crate::aot::Elvish;
93 pub use crate::aot::Fish;
94 pub use crate::aot::PowerShell;
95 pub use crate::aot::Shell;
96 pub use crate::aot::Zsh;
97}
98/// Deprecated, see [`aot::Generator`]
99pub use aot::Generator;
100/// Deprecated, see [`aot::Shell`]
101pub use aot::Shell;
102/// Deprecated, see [`aot::generate`]
103pub use aot::generate;
104/// Deprecated, see [`aot::generate_to`]
105pub use aot::generate_to;
106
107#[doc = include_str!("../README.md")]
108#[cfg(doctest)]
109pub struct ReadmeDoctests;