From 91c7a412f07c40aea563a16af0849a663b7cee6d Mon Sep 17 00:00:00 2001 From: Jonathan Dahan Date: Mon, 14 Jan 2019 03:28:48 -0500 Subject: [PATCH] Add support for spaces in commands (#75) For example "git commit". Fixes #74. --- src/main.rs | 5 +++-- tests/lib.rs | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 06c3f720..9784f76a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -44,7 +44,7 @@ const VERSION: &str = env!("CARGO_PKG_VERSION"); const USAGE: &str = " Usage: - tldr [options] + tldr [options] ... tldr [options] Options: @@ -79,7 +79,7 @@ const MAX_CACHE_AGE: i64 = 2_592_000; // 30 days #[derive(Debug, Deserialize)] struct Args { - arg_command: Option, + arg_command: Option>, flag_help: bool, flag_version: bool, flag_list: bool, @@ -303,6 +303,7 @@ fn main() { // Show command from cache if let Some(ref command) = args.arg_command { + let command = command.join("-"); // Check cache for freshness check_cache(&args, &cache); diff --git a/tests/lib.rs b/tests/lib.rs index 204c3fb8..4441236e 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -257,3 +257,21 @@ fn test_correct_rendering_with_config() { .success() .stdout(similar(expected)); } + +#[test] +fn test_spaces_find_command() { + let testenv = TestEnv::new(); + + testenv + .command() + .args(&["--update"]) + .assert() + .success() + .stdout(contains("Successfully updated cache.")); + + testenv + .command() + .args(&["git", "checkout"]) + .assert() + .success(); +}