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 #![doc(html_logo_url = "https://raw.githubusercontent.com/clap-rs/clap/master/assets/clap.png")] 9 #![doc = include_str!("../README.md")] 10 #![cfg_attr(docsrs, feature(doc_auto_cfg))] 11 #![warn(missing_docs, trivial_casts, unused_allocation, trivial_numeric_casts)] 12 #![forbid(unsafe_code)] 13 #![allow(clippy::needless_doctest_main)] 14 15 //! ## Quick Start 16 //! 17 //! - For generating at compile-time, see [`generate_to`] 18 //! - For generating at runtime, see [`generate`] 19 //! 20 //! [`Shell`] is a convenience `enum` for an argument value type that implements `Generator` 21 //! for each natively-supported shell type. 22 //! 23 //! ## Example 24 //! 25 //! ```rust,no_run 26 //! use clap::{Command, Arg, ValueHint, value_parser, ArgAction}; 27 //! use clap_complete::{generate, Generator, Shell}; 28 //! use std::io; 29 //! 30 //! fn build_cli() -> Command { 31 //! Command::new("example") 32 //! .arg(Arg::new("file") 33 //! .help("some input file") 34 //! .value_hint(ValueHint::AnyPath), 35 //! ) 36 //! .arg( 37 //! Arg::new("generator") 38 //! .long("generate") 39 //! .action(ArgAction::Set) 40 //! .value_parser(value_parser!(Shell)), 41 //! ) 42 //! } 43 //! 44 //! fn print_completions<G: Generator>(gen: G, cmd: &mut Command) { 45 //! generate(gen, cmd, cmd.get_name().to_string(), &mut io::stdout()); 46 //! } 47 //! 48 //! fn main() { 49 //! let matches = build_cli().get_matches(); 50 //! 51 //! if let Some(generator) = matches.get_one::<Shell>("generator").copied() { 52 //! let mut cmd = build_cli(); 53 //! eprintln!("Generating completion file for {generator}..."); 54 //! print_completions(generator, &mut cmd); 55 //! } 56 //! } 57 //! ``` 58 59 #![cfg_attr(docsrs, feature(doc_auto_cfg))] 60 #![warn(missing_docs)] 61 #![warn(clippy::print_stderr)] 62 #![warn(clippy::print_stdout)] 63 64 const INTERNAL_ERROR_MSG: &str = "Fatal internal error. Please consider filing a bug \ 65 report at https://github.com/clap-rs/clap/issues"; 66 67 #[macro_use] 68 #[allow(missing_docs)] 69 mod macros; 70 71 pub mod generator; 72 pub mod shells; 73 74 pub use generator::generate; 75 pub use generator::generate_to; 76 pub use generator::Generator; 77 pub use shells::Shell; 78 79 #[cfg(feature = "unstable-dynamic")] 80 pub mod dynamic; 81