1#[doc(no_inline)]
7pub use clap::ArgMatches;
8use clap::{App, Arg, SubCommand};
9
10pub fn build_setup<'a, 'b>() -> App<'a, 'b> {
14 return SubCommand::with_name("setup")
15 .arg(Arg::with_name("product").help("Product to setup").index(1))
16 .arg(
17 Arg::with_name("just")
18 .help("ignore dependncies")
19 .short("j")
20 .long("just"),
21 )
22 .arg(
23 Arg::with_name("relative")
24 .help("setup relative path")
25 .short("r")
26 .long("relative")
27 .takes_value(true),
28 )
29 .arg(
30 Arg::with_name("keep")
31 .help("keep exsisting setup products")
32 .short("k")
33 .long("keep"),
34 )
35 .arg(
36 Arg::with_name("tag")
37 .help("specify one or more tags to look up for products, evaluated left to right")
38 .short("t")
39 .long("tag")
40 .multiple(true)
41 .number_of_values(1)
42 .takes_value(true),
43 )
44 .arg(
45 Arg::with_name("inexact")
46 .help("Run setup with Inexact versions as specified in the table files")
47 .short("E")
48 .long("inexact"),
49 )
50 .arg(
51 Arg::with_name("verbose")
52 .short("v")
53 .long("verbose")
54 .multiple(true)
55 .help("Sets the level of verbosity, multiple occurances increases verbosity"),
56 );
57}
58
59fn build_list<'a, 'b>() -> App<'a, 'b> {
63 return SubCommand::with_name("list")
64 .arg(Arg::with_name("product")
65 .help("Name of product to list (optional)")
66 .index(1)
67 .conflicts_with_all(&["setup", "local"]))
68 .arg(Arg::with_name("setup")
69 .help("List only setup products")
70 .short("s")
71 .long("setup")
72 .conflicts_with_all(&["product", "local"]))
73 .arg(Arg::with_name("tags")
74 .help("List only these tags (does not include current)")
75 .short("t")
76 .long("tags")
77 .multiple(true)
78 .number_of_values(1)
79 .takes_value(true))
80 .arg(Arg::with_name("onlyTags")
81 .help("Only list product & tags (faster than tags and versions, but does not indicate setup tag)")
82 .long("onlyTags"))
83 .arg(Arg::with_name("onlyVers")
84 .help("Only list product & versions (faster than tags and versions)")
85 .long("onlyVers")
86 .conflicts_with("onlyTags"))
87 .arg(Arg::with_name("local")
88 .help("Only list products that are setup as local products")
89 .short("l")
90 .long("local")
91 .conflicts_with_all(&["product", "setup"]));
92}
93
94fn build_completions<'a, 'b>() -> App<'a, 'b> {
98 return SubCommand::with_name("completions")
99 .about("Creates auto completeion scripts for given shell")
100 .arg(
101 Arg::with_name("shell")
102 .required(true)
103 .possible_values(&["bash", "fish", "zsh", "elvish"])
104 .help("Shell to create completions for"),
105 );
106}
107
108fn build_env<'a, 'b>() -> App<'a, 'b> {
113 return SubCommand::with_name("env")
114 .about("Save or restore an existing reups environment")
115 .arg(
116 Arg::with_name("command")
117 .required(true)
118 .possible_values(&["save", "restore", "delete", "list"])
119 .help("Action to take for a given environment, to restore you most likely want to use the rrestore shell function"),
120 )
121 .arg(
122 Arg::with_name("name")
123 .required(false)
124 .help("Optional name to save/restore"),
125 )
126 .arg(
127 Arg::with_name("verbose")
128 .short("v")
129 .long("verbose")
130 .multiple(true)
131 .help("Sets the level of verbosity, multiple occurances increases verbosity"),
132 );
133}
134
135fn build_prep<'a, 'b>() -> App<'a, 'b> {
142 return SubCommand::with_name("prep");
143}
144
145pub fn build_cli() -> App<'static, 'static> {
149 App::new("Rust Eups")
150 .author("Nate Lust")
151 .about("Dynamic environment management")
152 .version(clap::crate_version!())
153 .subcommand(build_setup())
154 .subcommand(build_prep())
155 .subcommand(build_list())
156 .subcommand(build_completions())
157 .subcommand(build_env())
158}
159
160pub fn parse_args<'a>() -> ArgMatches<'a> {
165 let matches = build_cli().get_matches();
166 return matches;
167}