-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathmain.rs
233 lines (224 loc) · 9.15 KB
/
main.rs
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
use crate::errors::AppError;
use std::collections::BTreeSet;
fn main() {
unsafe {
openssl_probe::init_openssl_env_vars();
}
let return_code = _main();
std::process::exit(return_code)
}
fn _main() -> i32 {
let matches = crate::app::app().get_matches();
let config = config::read_config();
if config.is_err() {
eprintln!(
"Could not read v2.0 config: {:?}. If you are running the setup right now this is expected.",
config
);
};
let subcommand_name = matches.subcommand_name().expect("subcommand required by clap.rs").to_owned();
let subcommand_matches = matches.subcommand_matches(&subcommand_name).expect("subcommand matches enforced by clap.rs");
let result: Result<(), AppError> = match subcommand_name.as_ref() {
"sync" => {
let worker = subcommand_matches.get_one::<i32>("parallelism").expect("enforced by clap.rs").to_owned();
sync::synchronize(
config,
subcommand_matches.get_flag("only-new"),
!subcommand_matches.get_flag("no-fast-forward-merge"),
&subcommand_matches
.get_many::<String>("tag")
.unwrap_or_default()
.map(ToOwned::to_owned)
.collect(),
worker,
)
}
"add-remote" => {
let name: &str = subcommand_matches.get_one::<String>("NAME").expect("argument required by clap.rs");
let remote_name: &str = subcommand_matches.get_one::<String>("REMOTE_NAME").expect("argument required by clap.rs");
let url: &str = subcommand_matches.get_one::<String>("URL").expect("argument required by clap.rs");
project::add_remote(config, name, remote_name.to_string(), url.to_string())
}
"remove-remote" => {
let name: &str = subcommand_matches.get_one::<String>("NAME").expect("argument required by clap.rs");
let remote_name: &str = subcommand_matches.get_one::<String>("REMOTE_NAME").expect("argument required by clap.rs");
project::remove_remote(config, name, remote_name.to_string())
}
"add" => {
let name: Option<String> = subcommand_matches.get_one::<String>("NAME").map(ToOwned::to_owned);
let url: &str = subcommand_matches.get_one::<String>("URL").expect("argument required by clap.rs");
let after_workon: Option<String> = subcommand_matches.get_one::<String>("after-workon").map(ToOwned::to_owned);
let after_clone: Option<String> = subcommand_matches.get_one::<String>("after-clone").map(ToOwned::to_owned);
let override_path: Option<String> = subcommand_matches.get_one::<String>("override-path").map(ToOwned::to_owned);
let tags: Option<BTreeSet<String>> = subcommand_matches
.get_many::<String>("tag")
.map(|v| v.into_iter().map(ToOwned::to_owned).collect());
let trusted = subcommand_matches.get_flag("trusted");
project::add_entry(config, name, url, after_workon, after_clone, override_path, tags, trusted)
}
"remove" => project::remove_project(
config,
subcommand_matches.get_one::<String>("NAME").expect("argument required by clap.rs"),
subcommand_matches.get_flag("purge-directory"),
),
"move" => project::move_project(
config,
subcommand_matches.get_one::<String>("NAME").expect("argument required by clap.rs"),
subcommand_matches.get_one::<String>("DESTINATION").expect("argument required by clap.rs"),
),
"update" => {
let name: &str = subcommand_matches.get_one::<String>("NAME").expect("argument required by clap.rs");
let git: Option<String> = subcommand_matches.get_one::<String>("git").map(ToOwned::to_owned);
let after_workon: Option<String> = subcommand_matches.get_one::<String>("after-workon").map(ToOwned::to_owned);
let after_clone: Option<String> = subcommand_matches.get_one::<String>("after-clone").map(ToOwned::to_owned);
let override_path: Option<String> = subcommand_matches.get_one::<String>("override-path").map(ToOwned::to_owned);
project::update_entry(config, name, git, after_workon, after_clone, override_path)
}
"setup" => setup::setup(subcommand_matches.get_one::<String>("WORKSPACE_DIR").expect("argument required by clap.rs")),
"import" => setup::import(
config,
subcommand_matches.get_one::<String>("PROJECT_DIR").expect("argument required by clap.rs"),
),
"org-import" => setup::org_import(
config,
subcommand_matches.get_one::<String>("ORG_NAME").expect("argument required by clap.rs"),
subcommand_matches.get_flag("include-archived"),
),
"gen-workon" => workon::gen(
subcommand_matches.get_one::<String>("PROJECT_NAME").expect("argument required by clap.rs"),
config,
subcommand_matches.get_flag("quick"),
),
"gen-reworkon" => workon::gen_reworkon(config),
"reworkon" => workon::reworkon(config),
"inspect" => project::inspect(
subcommand_matches.get_one::<String>("PROJECT_NAME").expect("argument required by clap.rs"),
config,
subcommand_matches.get_flag("json"),
),
"projectile" => projectile::projectile(config),
"intellij" => intellij::intellij(config, !subcommand_matches.get_flag("no-warn")),
"print-path" => project::print_path(
config,
subcommand_matches.get_one::<String>("PROJECT_NAME").expect("argument required by clap.rs"),
),
"foreach" => spawn::foreach(
config,
subcommand_matches.get_one::<String>("CMD").expect("argument required by clap.rs"),
&subcommand_matches
.get_many::<String>("tag")
.unwrap_or_default()
.map(ToOwned::to_owned)
.collect(),
&subcommand_matches.get_one::<String>("parallel").map(ToOwned::to_owned),
),
"print-zsh-setup" => crate::shell::print_zsh_setup(subcommand_matches.get_flag("with-fzf"), subcommand_matches.get_flag("with-skim")),
"print-bash-setup" => crate::shell::print_bash_setup(subcommand_matches.get_flag("with-fzf"), subcommand_matches.get_flag("with-skim")),
"print-fish-setup" => crate::shell::print_fish_setup(subcommand_matches.get_flag("with-fzf"), subcommand_matches.get_flag("with-skim")),
"tag" => {
let subsubcommand_name: String = subcommand_matches.subcommand_name().expect("subcommand matches enforced by clap.rs").to_owned();
let subsubcommand_matches: clap::ArgMatches = subcommand_matches
.subcommand_matches(&subsubcommand_name)
.expect("subcommand matches enforced by clap.rs")
.to_owned();
execute_tag_subcommand(config, &subsubcommand_name, &subsubcommand_matches)
}
"ls" => project::ls(
config,
&subcommand_matches
.get_many::<String>("tag")
.unwrap_or_default()
.map(ToOwned::to_owned)
.collect(),
),
_ => Err(AppError::InternalError("Command not implemented")),
}
.map(|_| ());
match result {
Ok(()) => 0,
Err(error) => {
eprintln!("Error running command: error {}", error);
1
}
}
}
fn execute_tag_subcommand(maybe_config: Result<config::Config, AppError>, tag_command_name: &str, tag_matches: &clap::ArgMatches) -> Result<(), AppError> {
match tag_command_name {
"ls" => {
let maybe_project_name: Option<String> = tag_matches.get_one::<String>("PROJECT_NAME").map(ToOwned::to_owned);
tag::list_tags(maybe_config, maybe_project_name)
}
"tag-project" => {
let project_name: String = tag_matches
.get_one::<String>("PROJECT_NAME")
.map(ToOwned::to_owned)
.expect("argument enforced by clap.rs");
let tag_name: String = tag_matches
.get_one::<String>("tag-name")
.map(ToOwned::to_owned)
.expect("argument enforced by clap.rs");
tag::add_tag(&maybe_config?, project_name, tag_name)
}
"untag-project" => {
let project_name: String = tag_matches
.get_one::<String>("PROJECT_NAME")
.map(ToOwned::to_owned)
.expect("argument enforced by clap.rs");
let tag_name: String = tag_matches
.get_one::<String>("tag-name")
.map(ToOwned::to_owned)
.expect("argument enforced by clap.rs");
tag::remove_tag(maybe_config, project_name, &tag_name)
}
"inspect" => {
let tag_name: String = tag_matches
.get_one::<String>("tag-name")
.map(ToOwned::to_owned)
.expect("argument enforced by clap.rs");
tag::inspect_tag(maybe_config, &tag_name)
}
"rm" => {
let tag_name: String = tag_matches
.get_one::<String>("tag-name")
.map(ToOwned::to_owned)
.expect("argument enforced by clap.rs");
tag::delete_tag(maybe_config, &tag_name)
}
"add" => {
let tag_name: String = tag_matches
.get_one::<String>("tag-name")
.map(ToOwned::to_owned)
.expect("argument enforced by clap.rs");
let after_workon: Option<String> = tag_matches.get_one::<String>("after-workon").map(ToOwned::to_owned);
let after_clone: Option<String> = tag_matches.get_one::<String>("after-clone").map(ToOwned::to_owned);
let tag_workspace: Option<String> = tag_matches.get_one::<String>("workspace").map(ToOwned::to_owned);
let priority: Option<u8> = tag_matches.get_one::<u8>("priority").map(ToOwned::to_owned);
tag::create_tag(maybe_config, tag_name, after_workon, after_clone, priority, tag_workspace)
}
"autotag" => tag::autotag(
maybe_config,
tag_matches.get_one::<String>("CMD").expect("argument required by clap.rs"),
&tag_matches
.get_one::<String>("tag-name")
.map(ToOwned::to_owned)
.expect("argument enforced by clap.rs"),
&tag_matches.get_one::<String>("parallel").map(ToOwned::to_owned),
),
_ => Result::Err(AppError::InternalError("Command not implemented")),
}
}
mod app;
mod config;
mod errors;
mod git;
mod intellij;
mod project;
mod projectile;
mod setup;
mod shell;
mod spawn;
mod sync;
mod tag;
mod util;
mod workon;
mod ws;