From c57c0eb371935a00884d91ffad73161db6d0f43b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20N=2E=20Robalino?= Date: Wed, 11 Sep 2019 22:34:47 -0500 Subject: [PATCH] pass lint checks. --- src/cli.rs | 30 +++++++++++++++++++++++------- tests/filter_str_tests.rs | 6 ++---- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index 6d02119074..461524f49d 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -122,7 +122,6 @@ fn search_paths() -> Vec { let mut path = std::path::PathBuf::from("."); path.push("target"); path.push("release"); - search_paths.push(path); } @@ -137,9 +136,17 @@ fn load_plugins(context: &mut Context) -> Result<(), ShellError> { }; for path in search_paths() { - let pattern = path.join("nu_plugin_[a-z][a-z]*").clone(); + let mut pattern = path.to_path_buf(); - trace!("Trying {:?}", pattern.display()); + #[cfg(windows)] + { + pattern.push(std::path::Path::new("nu_plugin_[a-z]*.[a-z]*")); + } + + #[cfg(not(windows))] + { + pattern.push(std::path::Path::new("nu_plugin_[a-z]*")); + } match glob::glob_with(&pattern.to_string_lossy(), opts) { Err(_) => {} @@ -149,9 +156,16 @@ fn load_plugins(context: &mut Context) -> Result<(), ShellError> { continue; } - trace!("Found {:?}", bin.display()); - - let bin_name = bin.file_name().unwrap().to_string_lossy(); + let bin_name = { + if let Some(name) = bin.file_name() { + match name.to_str() { + Some(raw) => raw, + None => continue, + } + } else { + continue; + } + }; let is_valid_name = bin_name .chars() @@ -160,7 +174,8 @@ fn load_plugins(context: &mut Context) -> Result<(), ShellError> { let is_executable = { #[cfg(windows)] { - bin_name.ends_with(".exe") || bin_name.ends_with(".bat") + bin.ends_with(std::path::Path::new(".exe")) + || bin.ends_with(std::path::Path::new(".bat")) } #[cfg(not(windows))] @@ -170,6 +185,7 @@ fn load_plugins(context: &mut Context) -> Result<(), ShellError> { }; if is_valid_name && is_executable { + trace!("Trying {:?}", bin.display()); load_plugin(&bin, context)?; } } diff --git a/tests/filter_str_tests.rs b/tests/filter_str_tests.rs index 55563c2fa0..9f92186fa6 100644 --- a/tests/filter_str_tests.rs +++ b/tests/filter_str_tests.rs @@ -10,9 +10,7 @@ fn can_only_apply_one() { "open caco3_plastics.csv | first 1 | str origin --downcase --upcase" ); - assert!( - actual.contains("Usage: str field [--downcase|--upcase|--to-int") - ); + assert!(actual.contains("Usage: str field [--downcase|--upcase|--to-int")); } #[test] @@ -91,4 +89,4 @@ fn converts_to_int() { )); assert_eq!(actual, "2509000000"); -} \ No newline at end of file +}