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
use structopt::clap::AppSettings;
use structopt::StructOpt;
#[derive(StructOpt)]
pub struct Commit {
/// Sets the 'type' component of the commit (optional; otherwise interactive prompt)
#[structopt(short, long)]
pub ty: Option<String>,
/// Sets the 'scope' component of the commit (optional; otherwise interactive prompt)
#[structopt(short, long)]
pub scope: Option<String>,
/// Sets the main message component of the commit (optional; otherwise interactive prompt)
#[structopt(short, long)]
pub message: Option<String>,
#[structopt(short, long)]
pub all: bool,
/// Arguments which will be passed to 'git commit'.
/// Pass a '--' argument before the git args to disable special parsing.
#[structopt(short, long)]
pub git_args: Vec<String>,
}
#[derive(StructOpt)]
pub struct Log {
/// Filter by 'type' e.g. 'feat'
#[structopt(short, long)]
pub ty: Option<String>,
/// Filter by 'scope' e.g. 'client'
#[structopt(short, long)]
pub scope: Option<String>,
/// Number of commits to display.
#[structopt(short, long)]
pub num: Option<usize>,
/// Output log info as a JSON array of objects
#[structopt(short, long)]
pub json: bool,
/// Only useful when filing bug reports for glint.
#[structopt(short, long)]
pub debug: bool,
/// Arguments which will be passed to 'git log'. Note that certain
/// options will break the command. Passing file paths/prefixes is
/// typical usage.
pub git_args: Vec<String>,
}
/// A friendly conventional commit tool. You probably want the 'commit' subcommand, or 'c' for short.
#[derive(StructOpt)]
pub enum Cli {
/// Create a new commit
Commit(Commit),
/// View recent commits
Log(Log),
}
pub fn parse() -> Cli {
let matches = Cli::clap()
.setting(AppSettings::TrailingVarArg)
.setting(AppSettings::InferSubcommands)
.setting(AppSettings::SubcommandRequiredElseHelp)
.get_matches();
Cli::from_clap(&matches)
}