From 778bc279e44d418437d16635be1dd848dbaf01ef Mon Sep 17 00:00:00 2001 From: Hatter Jiang Date: Sun, 14 Jun 2020 00:22:05 +0800 Subject: [PATCH] add verbose in newcliapp --- Cargo.toml | 5 +++++ README.md | 10 +++++++++- src/Carto.toml_template | 2 +- src/cmd_newcliapp.rs | 9 +++++++++ 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 41bbbc7..6d015be 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,6 +3,11 @@ name = "buildrs" version = "0.1.0" authors = ["Hatter Jiang "] edition = "2018" +license = "MIT" +readme = "README.md" +keywords = ["buildrs"] +description = "buildrs is a Rust build tool" +repository = "https://git.hatter.ink/hatter/buildrs" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/README.md b/README.md index 99c8ac3..2c9ed04 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,11 @@ # buildrs -Build rust tool \ No newline at end of file +Build rust tool + + +Create cargo app: + +``` +% cargo r -- newcliapp app_name +``` + diff --git a/src/Carto.toml_template b/src/Carto.toml_template index 0d11f61..a019352 100644 --- a/src/Carto.toml_template +++ b/src/Carto.toml_template @@ -1,7 +1,7 @@ [package] name = "{{NAME}}" version = "0.1.0" -authors = ["Hatter Jiang "] +authors = ["Author Here!"] edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/src/cmd_newcliapp.rs b/src/cmd_newcliapp.rs index 7af9d51..479f7cd 100644 --- a/src/cmd_newcliapp.rs +++ b/src/cmd_newcliapp.rs @@ -25,6 +25,8 @@ impl Command for CommandNewCliApp { } fn run(&self, _arg_matches: &ArgMatches, sub_arg_matches: &ArgMatches) -> CommandError { + let is_verbose = sub_arg_matches.is_present("verbose"); + if is_file_exists(CARGO_TOML_FILE) || is_file_exists("src") { println!("[ERROR] File exists: {}, or dir exists: src/", CARGO_TOML_FILE); return Ok(()); @@ -33,13 +35,20 @@ impl Command for CommandNewCliApp { let app_name = sub_arg_matches.value_of("APP_NAME").expect("APP_NAME is required!"); let cargo_toml = CARGO_TOML.replace("{{NAME}}", app_name); + if is_verbose { println!("[INFO] Create dir: src/"); } fs::create_dir("src/")?; + if is_verbose { println!("[INFO] Create file: src/main.rs"); } fs::write("src/main.rs", MAIN_RS.as_bytes())?; + if is_verbose { println!("[INFO] Create file: src/cmd.rs"); } fs::write("src/cmd.rs", CMD_RS.as_bytes())?; + if is_verbose { println!("[INFO] Create file: src/cmd_default.rs"); } fs::write("src/cmd_default.rs", CMD_DEFAULT_RS.as_bytes())?; + if is_verbose { println!("[INFO] Create file: src/cmd_sample.rs"); } fs::write("src/cmd_sample.rs", CMD_SAMPLE_RS.as_bytes())?; + if is_verbose { println!("[INFO] Create file: Cargo.toml"); } fs::write(CARGO_TOML_FILE, cargo_toml.as_bytes())?; + println!("[INFO] Project created!"); Ok(()) } }