Skip to content

Commit d2d1e9f

Browse files
committed
init clap app in separate method
1 parent 8bd5e2f commit d2d1e9f

File tree

1 file changed

+29
-27
lines changed

1 file changed

+29
-27
lines changed

tmc-langs-cli/src/main.rs

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -18,32 +18,8 @@ use tmc_langs_util::{task_executor, Language};
1818
use url::Url;
1919
use walkdir::WalkDir;
2020

21-
#[quit::main]
22-
fn main() {
23-
env_logger::init();
24-
25-
if let Err(e) = run() {
26-
let mut causes = vec![];
27-
let mut next_source = e.source();
28-
while let Some(source) = next_source {
29-
causes.push(format!("Caused by: {}", source.to_string()));
30-
next_source = source.source();
31-
}
32-
let error = serde_json::json! {
33-
{
34-
"error": {
35-
"message": e.to_string(),
36-
"causes": causes,
37-
}
38-
}
39-
};
40-
println!("{:#}", error);
41-
quit::with_code(1);
42-
}
43-
}
44-
45-
fn run() -> Result<()> {
46-
let matches = App::new(env!("CARGO_PKG_NAME"))
21+
fn create_app() -> App<'static, 'static> {
22+
App::new(env!("CARGO_PKG_NAME"))
4723
.version(env!("CARGO_PKG_VERSION"))
4824
.author(env!("CARGO_PKG_AUTHORS"))
4925
.about(env!("CARGO_PKG_DESCRIPTION"))
@@ -435,8 +411,34 @@ fn run() -> Result<()> {
435411
.help("Required if save-old-state is set. The URL where the submission should be posted.")
436412
.long("submission-url")
437413
.takes_value(true))))
414+
}
438415

439-
.get_matches();
416+
#[quit::main]
417+
fn main() {
418+
env_logger::init();
419+
420+
if let Err(e) = run() {
421+
let mut causes = vec![];
422+
let mut next_source = e.source();
423+
while let Some(source) = next_source {
424+
causes.push(format!("Caused by: {}", source.to_string()));
425+
next_source = source.source();
426+
}
427+
let error = serde_json::json! {
428+
{
429+
"error": {
430+
"message": e.to_string(),
431+
"causes": causes,
432+
}
433+
}
434+
};
435+
println!("{:#}", error);
436+
quit::with_code(1);
437+
}
438+
}
439+
440+
fn run() -> Result<()> {
441+
let matches = create_app().get_matches();
440442

441443
// non-core
442444
if let Some(matches) = matches.subcommand_matches("checkstyle") {

0 commit comments

Comments
 (0)