1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
use clap::{App, AppSettings, Arg, SubCommand};

pub fn build_cli() -> App<'static, 'static> {
    let setup_subcommand = SubCommand::with_name("auth")
        .about("Setup Sherpa CLI")
        .arg(Arg::with_name("handle")
            .help("Github handle")
            .index(1)
            .required(true))
        .arg(Arg::with_name("token")
            .help("Personal Github Access Token\nThe token needs to have read:org permissions")
            .index(2)
            .required(true));

    let deploy_subcommand = SubCommand::with_name("deploy")
        .about("Deploy to a stage")
        .arg(Arg::with_name("trekker")
            .takes_value(true)
            .help("Trekker to use")
            .long("trekker"))
        .arg(Arg::with_name("branch")
            .takes_value(true)
            .help("Branch to deploy")
            .long("branch"))
        .arg(Arg::with_name("stage")
            .help("Sherpa stage")
            .index(1)
            .required(true));

    let stages_subcommand = SubCommand::with_name("stages")
        .about("Actions on stages")
        .subcommand(SubCommand::with_name("ls")
            .about("List stages")
            .arg(Arg::with_name("trekker")
                .takes_value(true)
                .help("Trekker to use")
                .long("trekker")))
        .setting(AppSettings::SubcommandRequired);

    let logs_subcommand = SubCommand::with_name("logs")
        .about("Logs for a stage")
        .arg(Arg::with_name("trekker")
            .takes_value(true)
            .help("Trekker to use")
            .long("trekker"))
        .arg(Arg::with_name("stage")
            .help("Sherpa stage")
            .index(1)
            .required(true));


    App::new("sherpa")
        .version(crate_version!())
        .setting(AppSettings::VersionlessSubcommands)
        .after_help("You can also run `sherpa SUBCOMMAND -h` to get more information about that \
                     subcommand.")
        .subcommand(setup_subcommand)
        .subcommand(deploy_subcommand)
        .subcommand(stages_subcommand)
        .subcommand(logs_subcommand)
        .arg(Arg::with_name("config")
            .takes_value(true)
            .help("Override config directory")
            .short("c")
            .long("config"))
        .arg(Arg::with_name("sherpa_stage")
            .takes_value(true)
            .help("Configure the Sherpa stage to use")
            .long("sherpa-stage"))
        .setting(AppSettings::SubcommandRequiredElseHelp)
}