]> git.proxmox.com Git - rustc.git/blob - src/vendor/clap/src/args/subcommand.rs
New upstream version 1.17.0+dfsg1
[rustc.git] / src / vendor / clap / src / args / subcommand.rs
1 // Third Party
2 #[cfg(feature = "yaml")]
3 use yaml_rust::Yaml;
4
5 // Internal
6 use App;
7 use ArgMatches;
8
9 /// The abstract representation of a command line subcommand.
10 ///
11 /// This struct describes all the valid options of the subcommand for the program. Subcommands are
12 /// essentially "sub-[`App`]s" and contain all the same possibilities (such as their own
13 /// [arguments], subcommands, and settings).
14 ///
15 /// # Examples
16 ///
17 /// ```rust
18 /// # use clap::{App, Arg, SubCommand};
19 /// App::new("myprog")
20 /// .subcommand(
21 /// SubCommand::with_name("config")
22 /// .about("Used for configuration")
23 /// .arg(Arg::with_name("config_file")
24 /// .help("The configuration file to use")
25 /// .index(1)))
26 /// # ;
27 /// ```
28 /// [`App`]: ./struct.App.html
29 /// [arguments]: ./struct.Arg.html
30 #[derive(Debug, Clone)]
31 pub struct SubCommand<'a> {
32 #[doc(hidden)]
33 pub name: String,
34 #[doc(hidden)]
35 pub matches: ArgMatches<'a>,
36 }
37
38 impl<'a> SubCommand<'a> {
39 /// Creates a new instance of a subcommand requiring a name. The name will be displayed
40 /// to the user when they print version or help and usage information.
41 ///
42 /// # Examples
43 ///
44 /// ```rust
45 /// # use clap::{App, Arg, SubCommand};
46 /// App::new("myprog")
47 /// .subcommand(
48 /// SubCommand::with_name("config"))
49 /// # ;
50 /// ```
51 pub fn with_name<'b>(name: &str) -> App<'a, 'b> { App::new(name) }
52
53 /// Creates a new instance of a subcommand from a YAML (.yml) document
54 ///
55 /// # Examples
56 ///
57 /// ```ignore
58 /// # #[macro_use]
59 /// # extern crate clap;
60 /// # use clap::Subcommand;
61 /// # fn main() {
62 /// let sc_yaml = load_yaml!("test_subcommand.yml");
63 /// let sc = SubCommand::from_yaml(sc_yaml);
64 /// # }
65 /// ```
66 #[cfg(feature = "yaml")]
67 pub fn from_yaml(yaml: &Yaml) -> App { App::from_yaml(yaml) }
68 }