• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #![warn(missing_docs, trivial_casts, unused_allocation, trivial_numeric_casts)]
11 #![forbid(unsafe_code)]
12 #![allow(clippy::needless_doctest_main)]
13 
14 //! ## Quick Start
15 //!
16 //! - For generating at compile-time, see [`generate_to`]
17 //! - For generating at runtime, see [`generate`]
18 //!
19 //! [`Shell`] is a convenience `enum` for an argument value type that implements `Generator`
20 //! for each natively-supported shell type.
21 //!
22 //! ## Example
23 //!
24 //! ```rust,no_run
25 //! use clap::{Command, Arg, ValueHint, value_parser, ArgAction};
26 //! use clap_complete::{generate, Generator, Shell};
27 //! use std::io;
28 //!
29 //! fn build_cli() -> Command {
30 //!     Command::new("example")
31 //!          .arg(Arg::new("file")
32 //!              .help("some input file")
33 //!                 .value_hint(ValueHint::AnyPath),
34 //!         )
35 //!        .arg(
36 //!            Arg::new("generator")
37 //!                .long("generate")
38 //!                .action(ArgAction::Set)
39 //!                .value_parser(value_parser!(Shell)),
40 //!        )
41 //! }
42 //!
43 //! fn print_completions<G: Generator>(gen: G, cmd: &mut Command) {
44 //!     generate(gen, cmd, cmd.get_name().to_string(), &mut io::stdout());
45 //! }
46 //!
47 //! fn main() {
48 //!     let matches = build_cli().get_matches();
49 //!
50 //!     if let Some(generator) = matches.get_one::<Shell>("generator").copied() {
51 //!         let mut cmd = build_cli();
52 //!         eprintln!("Generating completion file for {}...", generator);
53 //!         print_completions(generator, &mut cmd);
54 //!     }
55 //! }
56 //! ```
57 
58 const 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)]
63 mod macros;
64 
65 pub mod generator;
66 pub mod shells;
67 
68 pub use generator::generate;
69 pub use generator::generate_to;
70 pub use generator::Generator;
71 pub use shells::Shell;
72 
73 #[cfg(feature = "unstable-dynamic")]
74 pub mod dynamic;
75