diff --git a/Cargo.lock b/Cargo.lock index c8ef224..1324036 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -16,6 +16,11 @@ dependencies = [ "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "approx" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "assert_cmd" version = "0.11.1" @@ -81,6 +86,16 @@ name = "cfg-if" version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "cgmath" +version = "0.16.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "approx 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "clap" version = "2.33.0" @@ -95,6 +110,15 @@ dependencies = [ "vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "colored" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "winconsole 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "crossbeam-channel" version = "0.3.8" @@ -142,6 +166,11 @@ name = "fnv" version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "fuchsia-cprng" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "getrandom" version = "0.1.6" @@ -222,6 +251,7 @@ dependencies = [ "assert_cmd 0.11.1 (registry+https://github.com/rust-lang/crates.io-index)", "assert_fs 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)", "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)", + "colored 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "predicates 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "pulldown-cmark 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -236,6 +266,14 @@ name = "normalize-line-endings" version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "num-traits" +version = "0.1.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "num-traits" version = "0.2.8" @@ -306,6 +344,18 @@ dependencies = [ "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "rand" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "rand" version = "0.7.0" @@ -328,6 +378,19 @@ dependencies = [ "rand_core 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "rand_core" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rand_core" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "rand_core" version = "0.5.0" @@ -344,6 +407,14 @@ dependencies = [ "rand_core 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "rdrand" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "redox_syscall" version = "0.1.56" @@ -385,6 +456,11 @@ dependencies = [ "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "rgb" +version = "0.8.13" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "ryu" version = "1.0.0" @@ -571,9 +647,21 @@ name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "winconsole" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cgmath 0.16.1 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rgb 0.8.13 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", +] + [metadata] "checksum aho-corasick 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)" = "36b7aa1ccb7d7ea3f437cf025a2ab1c47cc6c1bc9fc84918ff449def12f5e282" "checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" +"checksum approx 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "08abcc3b4e9339e33a3d0a5ed15d84a687350c05689d825e0f6655eef9e76a94" "checksum assert_cmd 0.11.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2dc477793bd82ec39799b6f6b3df64938532fdf2ab0d49ef817eac65856a5a1e" "checksum assert_fs 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)" = "4ce6ba957da497523c08f8e0bd0f2e038d23ad6a3f7a391ed9d4afa9314838c0" "checksum atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "9a7d5b8723950951411ee34d271d99dddcc2035a16ab25310ea2c8cfd4369652" @@ -582,13 +670,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum bstr 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "fc0662252f9bba48c251a16d16a768b9fcd959593bde07544710bce6efe60b7a" "checksum c2-chacha 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7d64d04786e0f528460fc884753cf8dddcc466be308f6026f8e355c41a0e4101" "checksum cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "b486ce3ccf7ffd79fdeb678eac06a9e6c09fc88d33836340becb8fffe87c5e33" +"checksum cgmath 0.16.1 (registry+https://github.com/rust-lang/crates.io-index)" = "64a4b57c8f4e3a2e9ac07e0f6abc9c24b6fc9e1b54c3478cfb598f3d0023e51c" "checksum clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5067f5bb2d80ef5d68b4c87db81601f0b75bca627bc2ef76b141d7b846a3c6d9" +"checksum colored 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6cdb90b60f2927f8d76139c72dbde7e10c3a2bc47c8594c9c7a66529f2687c03" "checksum crossbeam-channel 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "0f0ed1a4de2235cabda8558ff5840bffb97fcb64c97827f354a451307df5f72b" "checksum crossbeam-utils 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "f8306fcef4a7b563b76b7dd949ca48f52bc1141aa067d2ea09565f3e2652aa5c" "checksum difference 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "524cbf6897b527295dff137cec09ecf3a05f4fddffd7dfcd1585403449e74198" "checksum escargot 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ceb9adbf9874d5d028b5e4c5739d22b71988252b25c9c98fe7cf9738bee84597" "checksum float-cmp 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "134a8fa843d80a51a5b77d36d42bc2def9edcb0262c914861d08129fd1926600" "checksum fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "2fad85553e09a6f881f739c29f0b00b0f01357c743266d478b68951ce23285f3" +"checksum fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" "checksum getrandom 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "e65cce4e5084b14874c4e7097f38cab54f47ee554f9194673456ea379dcc4c55" "checksum globset 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "925aa2cac82d8834e2b2a4415b6f6879757fb5c0928fc445ae76461a12eed8f2" "checksum globwalk 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "89fa2e29859da05acd066bd45996f05c271b271d7ec4a781f909682328f65d25" @@ -599,6 +690,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum log 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)" = "c275b6ad54070ac2d665eef9197db647b32239c9d244bfb6f041a766d00da5b3" "checksum memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2efc7bc57c883d4a4d6e3246905283d8dae951bb3bd32f49d6ef297f546e1c39" "checksum normalize-line-endings 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2e0a1a39eab95caf4f5556da9289b9e68f0aafac901b2ce80daaf020d3b733a8" +"checksum num-traits 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)" = "92e5113e9fd4cc14ded8e499429f396a20f98c772a47cc8622a736e1ec843c31" "checksum num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "6ba9a427cfca2be13aa6f6403b0b7e7368fe982bfa16fccc450ce74c46cd9b32" "checksum numtoa 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b8f8bdf33df195859076e54ab11ee78a1b208382d3a26ec40d142ffc1ecc49ef" "checksum ppv-lite86 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "e3cbf9f658cdb5000fcf6f362b8ea2ba154b9f146a61c7a20d647034c6b6561b" @@ -608,15 +700,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)" = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759" "checksum pulldown-cmark 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "051e60ace841b3bfecd402fe5051c06cb3bec4a6e6fdd060a37aa8eb829a1db3" "checksum quote 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)" = "6ce23b6b870e8f94f81fb0a363d65d86675884b34a09043c81e5562f11c1f8e1" +"checksum rand 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "552840b97013b1a26992c11eac34bdd778e464601a4c2054b5f0bff7c6761293" "checksum rand 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d47eab0e83d9693d40f825f86948aa16eff6750ead4bdffc4ab95b8b3a7f052c" "checksum rand_chacha 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e193067942ef6f485a349a113329140d0ab9e2168ce92274499bb0e9a4190d9d" +"checksum rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" +"checksum rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d0e7a549d590831370895ab7ba4ea0c1b6b011d106b5ff2da6eee112615e6dc0" "checksum rand_core 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "615e683324e75af5d43d8f7a39ffe3ee4a9dc42c5c701167a71dc59c3a493aca" "checksum rand_hc 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" +"checksum rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" "checksum redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)" = "2439c63f3f6139d1b57529d16bc3b8bb855230c8efcc5d3a896c8bea7c3b1e84" "checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76" "checksum regex 1.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "d9d8297cc20bbb6184f8b45ff61c8ee6a9ac56c156cec8e38c3e5084773c44ad" "checksum regex-syntax 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)" = "9b01330cce219c1c6b2e209e5ed64ccd587ae5c67bed91c0b49eecf02ae40e21" "checksum remove_dir_all 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "4a83fa3702a688b9359eccba92d153ac33fd2e8462f9e0e3fdf155239ea7792e" +"checksum rgb 0.8.13 (registry+https://github.com/rust-lang/crates.io-index)" = "4f089652ca87f5a82a62935ec6172a534066c7b97be003cc8f702ee9a7a59c92" "checksum ryu 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c92464b447c0ee8c4fb3824ecc8383b81717b9f1e74ba2e72540aef7b9f82997" "checksum same-file 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "585e8ddcedc187886a30fa705c47985c3fa88d06624095856b36ca0b82ff4421" "checksum serde 1.0.97 (registry+https://github.com/rust-lang/crates.io-index)" = "d46b3dfedb19360a74316866cef04687cd4d6a70df8e6a506c63512790769b72" @@ -643,3 +740,4 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" "checksum winapi-util 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7168bab6e1daee33b4557efd0e95d5ca70a03706d39fa5f3fe7a236f584b03c9" "checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +"checksum winconsole 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3ef84b96d10db72dd980056666d7f1e7663ce93d82fa33b63e71c966f4cf5032" diff --git a/Cargo.toml b/Cargo.toml index 76644c8..77d7ba8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,6 +17,7 @@ path = "src/lib.rs" [dependencies] clap = "2.33.0" # https://github.com/clap-rs/clap +colored = "1.8.0" # https://github.com/mackwic/colored pulldown-cmark = { version = "0.5", default-features = false } # https://github.com/raphlinus/pulldown-cmark [dev-dependencies] diff --git a/src/loader.rs b/src/loader.rs index 3fd042a..0081923 100644 --- a/src/loader.rs +++ b/src/loader.rs @@ -8,7 +8,7 @@ use std::path::Path; pub fn read_maskfile(maskfile: &Path) -> Result { let file = File::open(maskfile); if file.is_err() { - return Err("Expected a maskfile.md to exist in the current directory.".to_string()); + return Err("failed to open maskfile.md".to_string()); } let mut file = file.unwrap(); @@ -47,7 +47,7 @@ mod read_maskfile { let err = maskfile.unwrap_err(); - let expected_err = "Expected a maskfile.md to exist in the current directory."; + let expected_err = "failed to open maskfile.md"; assert_eq!(err, expected_err, "error message was wrong"); } } diff --git a/src/main.rs b/src/main.rs index f799a6a..175edb8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,40 +4,32 @@ use std::path::Path; use clap::{ crate_authors, crate_description, crate_name, crate_version, App, Arg, ArgMatches, SubCommand, }; +use colored::*; use mask::command::Command; fn main() { - let args: Vec = env::args().collect(); - - let maybe_maskfile = args.get(1); - let maybe_path = args.get(2); - - let maskfile_path = match (maybe_maskfile, maybe_path) { - (Some(a), Some(path)) if a == "--maskfile" => Path::new(path), - _ => Path::new("./maskfile.md"), - }; + let cli_app = App::new(crate_name!()) + .version(crate_version!()) + .author(crate_authors!()) + .about(crate_description!()) + .arg(custom_maskfile_path_arg()); - let maskfile = mask::loader::read_maskfile(maskfile_path); + let maskfile = find_maskfile(); if maskfile.is_err() { - return eprintln!("ERROR: {}", maskfile.unwrap_err()); + println!("{} no maskfile.md found", "WARNING:".yellow()); + // If the maskfile can't be found, at least parse for --version or --help + cli_app.get_matches(); + return; } let root_command = mask::parser::build_command_structure(maskfile.unwrap()); - - let cli_app = App::new(crate_name!()) - .version(crate_version!()) - .author(crate_authors!()) - .about(crate_description!()); - let matches = build_subcommands(cli_app, &root_command.subcommands).get_matches(); - let chosen_cmd = find_command(&matches, &root_command.subcommands); - if chosen_cmd.is_none() { - // TODO: echo --help for root command - println!("Missing SUBCOMMAND"); - return; + // Exit with an error + eprintln!("{} missing subcommand", "ERROR:".red()); + std::process::exit(1); } match mask::executor::execute_command(chosen_cmd.unwrap()) { @@ -45,10 +37,40 @@ fn main() { Some(code) => std::process::exit(code), None => return, }, - Err(err) => eprintln!("ERROR: {}", err), + Err(err) => eprintln!("{} {}", "ERROR:".red(), err), } } +fn find_maskfile() -> Result { + let args: Vec = env::args().collect(); + + let maybe_maskfile = args.get(1); + let maybe_path = args.get(2); + + // Check for a custom --maskfile arg + let maskfile_path = match (maybe_maskfile, maybe_path) { + (Some(a), Some(path)) if a == "--maskfile" => Path::new(path), + _ => Path::new("./maskfile.md"), + }; + + let maskfile = mask::loader::read_maskfile(maskfile_path); + + maskfile +} + +fn custom_maskfile_path_arg<'a, 'b>() -> Arg<'a, 'b> { + // This is needed to prevent clap from complaining about the custom flag check + // within find_maskfile(). It should be removed once clap 3.x is released. + // See https://github.com/clap-rs/clap/issues/748 + let custom_maskfile_path = Arg::with_name("maskfile") + .help("Path to a different maskfile you want to use") + .long("maskfile") + .takes_value(true) + .multiple(false); + + custom_maskfile_path +} + fn build_subcommands<'a, 'b>( mut cli_app: App<'a, 'b>, subcommands: &'a Vec, @@ -78,16 +100,7 @@ fn build_subcommands<'a, 'b>( cli_app = cli_app.subcommand(subcmd); } - // This is needed to prevent clap from complaining. It should be removed once - // clap 3.x is released. See https://github.com/clap-rs/clap/issues/748 - let custom_maskfile_path = Arg::with_name("maskfile") - .help("Path to a different maskfile you want to use") - .short("m") - .long("maskfile") - .takes_value(true) - .multiple(false); - - cli_app.arg(custom_maskfile_path) + cli_app } fn find_command<'a>(matches: &ArgMatches, subcommands: &Vec) -> Option { diff --git a/tests/integration_test.rs b/tests/integration_test.rs index cc1eb87..eaf3497 100644 --- a/tests/integration_test.rs +++ b/tests/integration_test.rs @@ -1,4 +1,8 @@ +use std::path::PathBuf; + use assert_cmd::prelude::*; +use clap::{crate_name, crate_version}; +use colored::*; use predicates::str::contains; mod common; @@ -15,14 +19,54 @@ fn specifying_a_maskfile_in_a_different_dir() { ); common::run_mask(&maskfile_path) - .arg("--maskfile") - .arg(maskfile_path) .arg("--help") .assert() .stdout(contains("USAGE:")) .success(); } +mod when_no_maskfile_found { + use super::*; + + #[test] + fn logs_warning_about_missing_file() { + common::run_mask(&PathBuf::from("./nonexistent.md")) + .assert() + .stdout(contains(format!( + "{} no maskfile.md found", + "WARNING:".yellow() + ))) + .success(); + } + + #[test] + fn exits_without_error_for_help() { + common::run_mask(&PathBuf::from("./nonexistent.md")) + .command("--help") + .assert() + .stdout(contains("USAGE:")) + .success(); + } + + #[test] + fn exits_without_error_for_version() { + common::run_mask(&PathBuf::from("./nonexistent.md")) + .command("--version") + .assert() + .stdout(contains(format!("{} {}", crate_name!(), crate_version!()))) + .success(); + } + + #[test] + fn exits_with_error_for_any_other_command() { + common::run_mask(&PathBuf::from("./nonexistent.md")) + .command("yasss") + .assert() + .stderr(contains("error: Found argument 'yasss' which wasn't expected, or isn't valid in this context")) + .failure(); + } +} + mod exits_with_the_child_process_status_code { use super::*; diff --git a/tests/subcommands_test.rs b/tests/subcommands_test.rs index a0d6aeb..1adfdf7 100644 --- a/tests/subcommands_test.rs +++ b/tests/subcommands_test.rs @@ -1,4 +1,5 @@ use assert_cmd::prelude::*; +use colored::*; use predicates::str::contains; mod common; @@ -38,3 +39,17 @@ echo "Stopping service $service_name" .stdout(contains("Starting service my_fancy_service")) .success(); } + +#[test] +fn exits_with_error_when_missing_subcommnad() { + let (_temp, maskfile_path) = common::maskfile( + r#" +## foo +"#, + ); + + common::run_mask(&maskfile_path) + .assert() + .stderr(contains(format!("{} missing subcommand", "ERROR:".red()))) + .failure(); +}