From 6be924cda6a69d74ca1728582f9f249f9b6299c3 Mon Sep 17 00:00:00 2001 From: Jonathan Dahan Date: Mon, 17 Sep 2018 01:54:55 -0400 Subject: [PATCH 1/8] add -q, --quiet flag to surpress non-error output --- CHANGELOG.md | 3 +++ Cargo.toml | 2 +- bash_tealdeer | 2 +- src/main.rs | 19 ++++++++++++++----- 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 905f1ed53..0b1d64bb6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,9 @@ Possible log types: - `[fixed]` for any bug fixes. - `[security]` to invite users to upgrade in case of vulnerabilities. +### v1.1.0 (unreleased) + +- [added] --quiet,-q option to surpress most non-error messages ### v1.0.0 (2018-02-11) diff --git a/Cargo.toml b/Cargo.toml index f2c142b18..f1c21a20d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,7 +6,7 @@ license = "MIT/Apache-2.0" name = "tealdeer" readme = "README.md" repository = "https://github.com/dbrgn/tealdeer/" -version = "1.0.0" +version = "1.1.0" include = ["/src/**/*", "/tests/**/*", "/Cargo.toml", "/README.md", "/LICENSE-*", "/screenshot.png", "/bash_tealdeer"] [[bin]] diff --git a/bash_tealdeer b/bash_tealdeer index 05d298e1f..64efb0805 100644 --- a/bash_tealdeer +++ b/bash_tealdeer @@ -6,7 +6,7 @@ _tealdeer() _init_completion || return case $prev in - -h|--help|-v|--version|-l|--list|-u|--update|-c|--clear-cache|--config-path|--seed-config) + -h|--help|-v|--version|-l|--list|-u|--update|-c|--clear-cache|--config-path|--seed-config|-q|--quiet) return ;; -f|--render) diff --git a/src/main.rs b/src/main.rs index 9ce2d32d7..86b6cd14e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -75,6 +75,7 @@ Options: -o --os Override the operating system [linux, osx, sunos] -u --update Update the local cache -c --clear-cache Clear the local cache + -q --quiet Surpress informational messages --config-path Show config file path --seed-config Create a basic config @@ -105,6 +106,7 @@ struct Args { flag_os: Option, flag_update: bool, flag_clear_cache: bool, + flag_quiet: bool, flag_config_path: bool, flag_seed_config: bool, } @@ -142,6 +144,7 @@ fn check_cache(args: &Args, cache: &Cache) { if !args.flag_update { match cache.last_update() { Some(ago) if ago > MAX_CACHE_AGE => { + if args.flag_quiet { return; } println!("{}", Color::Red.paint(format!( "Cache wasn't updated in {} days.\n\ You should probably run `tldr --update` soon.", @@ -207,7 +210,9 @@ fn main() { }; process::exit(1); }); - println!("Successfully deleted cache."); + if !args.flag_quiet { + println!("Successfully deleted cache."); + } } // Update cache, pass through @@ -219,7 +224,9 @@ fn main() { }; process::exit(1); }); - println!("Successfully updated cache."); + if !args.flag_quiet { + println!("Successfully updated cache."); + } } // Render local file and exit @@ -266,9 +273,11 @@ fn main() { process::exit(0); } } else { - println!("Page {} not found in cache", &command); - println!("Try updating with `tldr --update`, or submit a pull request to:"); - eprintln!("https://github.com/tldr-pages/tldr"); + if !args.flag_quiet { + println!("Page {} not found in cache", &command); + println!("Try updating with `tldr --update`, or submit a pull request to:"); + println!("https://github.com/tldr-pages/tldr"); + } process::exit(1); } } From 16eb9ae34d3bbbd1340428703a4923e35cea24d8 Mon Sep 17 00:00:00 2001 From: Jonathan Dahan Date: Mon, 17 Sep 2018 01:57:40 -0400 Subject: [PATCH 2/8] add missing lock --- Cargo.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 13e8dfdfd..b08427e22 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -657,7 +657,7 @@ dependencies = [ [[package]] name = "tealdeer" -version = "1.0.0" +version = "1.1.0" dependencies = [ "ansi_term 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)", "assert_cli 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)", From 5ef672352886d9366c2da24f28136a1754f567f4 Mon Sep 17 00:00:00 2001 From: Danilo Bargen Date: Mon, 17 Sep 2018 08:51:50 +0200 Subject: [PATCH 3/8] Revert "add missing lock" This reverts commit 16eb9ae34d3bbbd1340428703a4923e35cea24d8. --- Cargo.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index b08427e22..13e8dfdfd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -657,7 +657,7 @@ dependencies = [ [[package]] name = "tealdeer" -version = "1.1.0" +version = "1.0.0" dependencies = [ "ansi_term 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)", "assert_cli 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)", From 29dd5c262c5cc5bba0ffdd60fbb3bddf56c54ad7 Mon Sep 17 00:00:00 2001 From: Danilo Bargen Date: Mon, 17 Sep 2018 08:52:42 +0200 Subject: [PATCH 4/8] Undo version bump --- CHANGELOG.md | 4 ++-- Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0b1d64bb6..ba3507902 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,9 +11,9 @@ Possible log types: - `[fixed]` for any bug fixes. - `[security]` to invite users to upgrade in case of vulnerabilities. -### v1.1.0 (unreleased) +### Unreleased -- [added] --quiet,-q option to surpress most non-error messages +- [added] New --quiet / -q option to surpress most non-error messages ### v1.0.0 (2018-02-11) diff --git a/Cargo.toml b/Cargo.toml index f1c21a20d..f2c142b18 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,7 +6,7 @@ license = "MIT/Apache-2.0" name = "tealdeer" readme = "README.md" repository = "https://github.com/dbrgn/tealdeer/" -version = "1.1.0" +version = "1.0.0" include = ["/src/**/*", "/tests/**/*", "/Cargo.toml", "/README.md", "/LICENSE-*", "/screenshot.png", "/bash_tealdeer"] [[bin]] From 232c0e5b4542e33b9787c07fa28cb33f9c7fe13e Mon Sep 17 00:00:00 2001 From: Danilo Bargen Date: Mon, 17 Sep 2018 08:53:57 +0200 Subject: [PATCH 5/8] Fix typo: surpress -> suppress --- CHANGELOG.md | 2 +- src/main.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ba3507902..09b953750 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,7 +13,7 @@ Possible log types: ### Unreleased -- [added] New --quiet / -q option to surpress most non-error messages +- [added] New --quiet / -q option to suppress most non-error messages ### v1.0.0 (2018-02-11) diff --git a/src/main.rs b/src/main.rs index 86b6cd14e..0d7f0254d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -75,7 +75,7 @@ Options: -o --os Override the operating system [linux, osx, sunos] -u --update Update the local cache -c --clear-cache Clear the local cache - -q --quiet Surpress informational messages + -q --quiet Suppress informational messages --config-path Show config file path --seed-config Create a basic config From 269ce7b532971408bd5219ae3de9316f018d07a8 Mon Sep 17 00:00:00 2001 From: Danilo Bargen Date: Mon, 17 Sep 2018 08:54:24 +0200 Subject: [PATCH 6/8] Add -q command to README --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 4e959a791..faa216c9f 100644 --- a/README.md +++ b/README.md @@ -70,6 +70,7 @@ These are the clients I tried but failed to compile or run: -o --os Override the operating system [linux, osx, sunos] -u --update Update the local cache -c --clear-cache Clear the local cache + -q --quiet Suppress informational messages --config-path Show config file path --seed-config Create a basic config From f09eb0c87ee9525640a340962c165096514be8ed Mon Sep 17 00:00:00 2001 From: Jonathan Dahan Date: Mon, 17 Sep 2018 12:53:34 -0400 Subject: [PATCH 7/8] Add tests for quiet option --- Cargo.lock | 12 ++++++++++ Cargo.toml | 1 + tests/lib.rs | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 80 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 13e8dfdfd..6553d18e2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -673,6 +673,7 @@ dependencies = [ "tempdir 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)", "toml 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "utime 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "walkdir 2.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "xdg 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -772,6 +773,16 @@ name = "utf8-ranges" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "utime" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "vcpkg" version = "0.2.2" @@ -945,6 +956,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "382810877fe448991dfc7f0dd6e3ae5d58088fd0ea5e35189655f84e6814fa56" "checksum url 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fa35e768d4daf1d85733418a49fb42e10d7f633e394fccab4ab7aba897053fe2" "checksum utf8-ranges 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "662fab6525a98beff2921d7f61a39e7d59e0b425ebc7d0d9e66d316e55124122" +"checksum utime 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4a9c0ddf7a5a39cd0c316dac124303d71fa197f8607027546c3be3e1c6f7bd9b" "checksum vcpkg 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9e0a7d8bed3178a8fb112199d466eeca9ed09a14ba8ad67718179b4fd5487d0b" "checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" "checksum walkdir 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)" = "bb08f9e670fab86099470b97cd2b252d6527f0b3cc1401acdb595ffc9dd288ff" diff --git a/Cargo.toml b/Cargo.toml index f2c142b18..018b5b3b3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,6 +32,7 @@ xdg = "2.1.0" [dev-dependencies] tempdir = "^0.3" assert_cli = "^0.5" +utime = "0.2.0" [features] dev = ["clippy"] diff --git a/tests/lib.rs b/tests/lib.rs index 6c3f51b39..016f44afb 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -2,6 +2,8 @@ extern crate assert_cli; extern crate tempdir; +extern crate utime; +extern crate time; use std::fs::File; use std::io::Write; @@ -67,6 +69,71 @@ fn test_update_cache() { .unwrap(); } +#[test] +fn test_quiet_cache() { + let testenv = TestEnv::new(); + testenv + .assert() + .with_args(&["--update", "--quiet"]) + .succeeds() + .stdout().is("") + .unwrap(); + + testenv + .assert() + .with_args(&["--clear-cache", "--quiet"]) + .succeeds() + .stdout().is("") + .unwrap(); +} + +#[test] +fn test_quiet_failures() { + let testenv = TestEnv::new(); + + testenv + .assert() + .with_args(&["--update", "-q"]) + .succeeds() + .stdout().is("") + .unwrap(); + + testenv + .assert() + .with_args(&["fakeprogram", "-q"]) + .fails() + .stdout().is("") + .unwrap(); +} + +#[test] +fn test_quiet_old_cache() { + let testenv = TestEnv::new(); + + testenv + .assert() + .with_args(&["--update", "-q"]) + .succeeds() + .stdout().is("") + .unwrap(); + + let _ = utime::set_file_times(testenv.cache_dir.path().join("tldr-master"), 1, 1).unwrap(); + + testenv + .assert() + .with_args(&["tldr"]) + .succeeds() + .stdout().contains("Cache wasn't updated in ") + .unwrap(); + + testenv + .assert() + .with_args(&["tldr", "--quiet"]) + .succeeds() + .stdout().doesnt_contain("Cache wasn't updated in ") + .unwrap(); +} + #[test] fn test_setup_seed_config() { let testenv = TestEnv::new(); From 882a4c662818e9a0c8b65c8283f955dc2c193f8b Mon Sep 17 00:00:00 2001 From: Jonathan Dahan Date: Mon, 17 Sep 2018 13:43:50 -0400 Subject: [PATCH 8/8] remove unnecessary extern crate in test --- tests/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/lib.rs b/tests/lib.rs index 016f44afb..cc0232e1b 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -3,7 +3,6 @@ extern crate assert_cli; extern crate tempdir; extern crate utime; -extern crate time; use std::fs::File; use std::io::Write;