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
use clap::{Arg, ArgAction, ArgMatches, Command, SubCommand};
use std::string::String;
const PROGRAM_DESC: &str = "Convenient utils for saving and install dotfiles";
const PROGRAM_NAME: &str = "dotfiles";
pub fn command() -> Result<ArgMatches, String> {
let cli: Command = Command::new(PROGRAM_NAME)
.version("0.1.0")
.author("Douglas Wu <wckdouglas@gmail.com>")
.about(PROGRAM_DESC)
.arg(
Arg::with_name("dotfile_yaml")
.help("A yaml file containing the dotfile names (see data/dotfiles.yaml)")
.long("dotfile-yaml")
.short('y')
.takes_value(true)
.required(true),
)
.subcommand(
// the first subcommand is to save the
// needed config files into a new dir
SubCommand::with_name("save")
.about("Save dotfiles into a folder")
.arg(
Arg::with_name("dest_dir")
.help("The destination directory to save for copying the dotfiles to")
.short('d')
.long("dest-dir")
.takes_value(true)
.required(true),
)
.arg(
Arg::with_name("dry")
.help("Dry run")
.long("dry-run")
.takes_value(false)
.required(false)
.action(ArgAction::SetTrue),
)
)
.subcommand(
SubCommand::with_name("apply-gh")
// the second subcommand is to clone a github dotfile repo
// and apply the files
.about("Applying dotfiles from a github url")
.arg(
Arg::with_name("url")
.help("The github url")
.short('u')
.long("url")
.takes_value(true)
.required(true),
)
.arg(
Arg::with_name("ssh_key")
.help("The ssh key to use, the private key file, should have a .pub file in the same folder too (default: ~/.ssh/id_rsa)")
.short('s')
.long("ssh-key")
.takes_value(true)
.required(false)
)
.arg(
Arg::with_name("dry")
.help("Dry run")
.long("dry-run")
.short('n')
.takes_value(false)
.required(false)
.action(ArgAction::SetTrue)
),
)
.subcommand(
SubCommand::with_name("apply")
// the second subcommand is to clone a github dotfile repo
// and apply the files
.about("Applying dotfiles from a cloned dotfiles dir")
.arg(
Arg::with_name("dir")
.help("The directory to dotfiles")
.short('d')
.long("dir")
.takes_value(true)
.required(true),
)
.arg(
Arg::with_name("dry")
.help("Dry run")
.long("dry-run")
.short('n')
.takes_value(false)
.required(false)
.action(ArgAction::SetTrue)
),
);
Ok(cli.get_matches())
}