summaryrefslogtreecommitdiffstats
path: root/src/cli.rs
blob: 871f9412245ddb4ef4c99f5d0085ee9c81695181 (plain)
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
use clap::{App, Arg, ArgGroup, SubCommand};

pub fn build_cli<'a>() -> App<'a, 'a> {
    App::new("repolocli")
        .version("0.1")
        .author("Matthias Beyer <mail@beyermatthias.de>")
        .about("Query repology.org and postprocess its output")

        .arg(Arg::with_name("config")
            .long("config")
            .value_name("PATH")
            .required(false)
            .multiple(false)
            .takes_value(true)
            .help("Override default configuration file path")

        )

        .arg(Arg::with_name("verbose")
                 .long("verbose")
                 .short("v")
                 .required(false)
                 .multiple(true)
                 .takes_value(false)
                 .help("Increase verbosity. Default = Info, -v = Debug, -vv = Trace")
        )

        .arg(Arg::with_name("quiet")
            .long("quiet")
            .short("q")
            .required(false)
            .multiple(true)
            .takes_value(false)
            .help("Decrease verbosity. Default = Info, -q = Warn, -qq = Error")
        )

        .arg(Arg::with_name("output")
            .long("output")
            .short("o")
            .required(false)
            .multiple(false)
            .takes_value(true)
            .possible_values(&["table", "json", "lines"])
            .default_value("lines")
            .help("Output format")
        )

        .arg(Arg::with_name("input_stdin")
            .long("stdin")
            .short("I")
            .required(false)
            .multiple(false)
            .takes_value(false)
            .help("Read data (JSON) from stdin.")
        )

        .subcommand(SubCommand::with_name("project")
            .arg(Arg::with_name("project_name")
                .index(1)
                .required(false) // TODO: Make required, is not required currently when --stdin is passed.
                .multiple(false)
                .takes_value(true)
                .help("Query data about a project")
            )

            .arg(Arg::with_name("sort-version")
                .long("sort-version")
                .required(false)
                .multiple(false)
                .takes_value(false)
                .help("Sort output by version")
                .conflicts_with("sort-repo")
            )
            .arg(Arg::with_name("sort-repo")
                .long("sort-repo")
                .required(false)
                .multiple(false)
                .takes_value(false)
                .help("Sort output by repository")
                .conflicts_with("sort-version")
            )
            .arg(Arg::with_name("latest")
                .long("latest")
                .required(false)
                .multiple(false)
                .takes_value(false)
                .help("Try to find the lastest version (version is string-compared if not used with --semver)")
                .conflicts_with("sort-version")
                .conflicts_with("sort-repo")
            )
            .arg(Arg::with_name("semver")
                .long("semver")
                .required(false)
                .multiple(false)
                .takes_value(false)
                .requires("latest")
                .help("Try to find latest version using semver. If semver could not be parsed, equality is assumed, which might yield bogus results.")
            )
        )

        .subcommand(SubCommand::with_name("problems")
            .arg(Arg::with_name("repo")
                .short("r")
                .long("repo")
                .alias("repository")
                .required(false)
                .multiple(false)
                .takes_value(true)
                .help("The repository to get problems for")
            )

            .arg(Arg::with_name("maintainer")
                .short("m")
                .long("maintainer")
                .alias("maint")
                .required(false)
                .multiple(false)
                .takes_value(true)
                .help("The maintainer to get problems for")
            )

            .group(ArgGroup::with_name("problems-args")
                .args(&["repo", "maintainer"])
                .required(true))


            .arg(Arg::with_name("sort-maintainer")
                .long("sort-maintainer")
                .required(false)
                .multiple(false)
                .takes_value(false)
                .help("Sort output by maintainer")
                .conflicts_with("sort-repo")
            )
            .arg(Arg::with_name("sort-repo")
                .long("sort-repo")
                .required(false)
                .multiple(false)
                .takes_value(false)
                .help("Sort output by repository")
                .conflicts_with("sort-maintainer")
            )
        )

        .after_help(r#"
        repolocli can read data from stdin, if you want to postprocess repology.org data you already
        fetched from repology.org/api/v1 via curl (or some other method).
        In this case, repolocli is only a easier-to-use 'jq' (if you don't know jq, look it up NOW!).
        "#)
}