diff --git a/Taskfile.yml b/Taskfile.yml index 0931417..97f6065 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -6,7 +6,7 @@ tasks: cmds: - cargo clippy lint:fix: - desc: Lint code + desc: Lint code and fix problems with autofixes cmds: - cargo clippy --fix --allow-staged --allow-dirty @@ -25,6 +25,11 @@ tasks: cmds: - cargo test + run: + desc: "Run the CLI with a debug build: task run -- <...args>" + cmds: + - cargo run + build: desc: Build debug artifacts sources: diff --git a/src/archives.rs b/src/archives.rs index bc3ce81..060641a 100644 --- a/src/archives.rs +++ b/src/archives.rs @@ -26,16 +26,16 @@ pub fn extract_archive(bytes: Response, path: &Path) -> Result<()> { for i in 0..archive.len() { let mut item = archive.by_index(i).unwrap(); - let file_path = item.sanitized_name(); + let file_path = item.mangled_name(); let file_path = file_path.to_string_lossy(); let mut new_path = path.to_owned(); if let Some(index) = file_path.find('\\') { - new_path.push(file_path[index + 1..].to_owned()); + new_path.push(&file_path[index + 1..]); } if item.is_dir() && !new_path.exists() { - create_dir_all(new_path.to_owned()) + create_dir_all(&new_path) .unwrap_or_else(|_| panic!("Could not create new folder: {:?}", new_path)); } @@ -52,7 +52,7 @@ pub fn extract_archive(bytes: Response, path: &Path) -> Result<()> { path.to_str() .unwrap() .strip_prefix("\\\\?\\") - .unwrap_or(path.to_str().unwrap()) + .unwrap_or_else(|| path.to_str().unwrap()) ); Result::Ok(()) diff --git a/src/main.rs b/src/main.rs index eef6623..d6e8500 100644 --- a/src/main.rs +++ b/src/main.rs @@ -94,7 +94,7 @@ impl Config { fn ensure_dir_exists(path: &Path) { if !path.exists() { - create_dir_all(path.to_path_buf()) + create_dir_all(path) .unwrap_or_else(|err| panic!("Could not create {:?} - {}", path, err)); println!("Created nvm dir at {:?}", path); diff --git a/src/node_version.rs b/src/node_version.rs index 119721b..b721ad2 100644 --- a/src/node_version.rs +++ b/src/node_version.rs @@ -79,7 +79,7 @@ impl OnlineNodeVersion { let url = format!( "https://nodejs.org/dist/v{}/{}", - self.version.to_string(), + self.version, file_name ); @@ -90,7 +90,7 @@ impl OnlineNodeVersion { fn get_file(&self) -> String { format!( "node-v{version}-win-{arch}.zip", - version = self.version().to_string(), + version = self.version(), arch = if cfg!(target_arch = "x86") { "x86" } else { diff --git a/src/subcommand/install.rs b/src/subcommand/install.rs index 5054e3c..f87f15b 100644 --- a/src/subcommand/install.rs +++ b/src/subcommand/install.rs @@ -23,8 +23,8 @@ pub struct InstallCommand { #[clap(validator = node_version::is_version_range)] pub version: Range, /// Switch to the new version after installing it - #[clap(long, short)] - pub switch: Option, + #[clap(long, short, default_value("false"))] + pub switch: bool, } impl Action for InstallCommand { @@ -55,12 +55,11 @@ impl Action for InstallCommand { )?; if config.force - || (options.switch.is_none() + || (options.switch && dialoguer::Confirm::new() .with_prompt(format!("Switch to {}?", version_to_install.to_string())) .default(true) .interact()?) - || options.switch.unwrap() { SwitchCommand::run( &config.with_force(), diff --git a/src/subcommand/list.rs b/src/subcommand/list.rs index 20edfe3..fc5d7d4 100644 --- a/src/subcommand/list.rs +++ b/src/subcommand/list.rs @@ -41,10 +41,10 @@ setting = AppSettings::ColoredHelp pub struct ListCommand { /// Only display installed versions #[clap(short, long)] - pub installed: Option, + pub installed: bool, /// Only display available versions #[clap(short, long, takes_value(false))] - pub online: Option, + pub online: bool, /// Filter by semantic versions. /// /// `12`, `^10.9`, `>=8.10`, `>=8, <9` diff --git a/src/subcommand/parse_version.rs b/src/subcommand/parse_version.rs index 0a12019..7c4461f 100644 --- a/src/subcommand/parse_version.rs +++ b/src/subcommand/parse_version.rs @@ -25,7 +25,7 @@ impl Action for ParseVersionCommand { "{:^pad$}\n{:^pad$}\n{}", options.version, "⬇", - result.to_string(), + result, pad = result.to_string().len() ); Ok(()) @@ -34,7 +34,7 @@ impl Action for ParseVersionCommand { println!( "Failed to parse `{}`: `{}`", options.version, - err.to_string() + err ); Ok(()) }, diff --git a/src/subcommand/switch.rs b/src/subcommand/switch.rs index f8e4681..7226f27 100644 --- a/src/subcommand/switch.rs +++ b/src/subcommand/switch.rs @@ -64,7 +64,7 @@ fn set_shims(config: &Config, version: &Version) -> Result<()> { } if read_link(&shims_dir).is_ok() { - if let Result::Err(err) = remove_dir(shims_dir.to_owned()) { + if let Result::Err(err) = remove_dir(&shims_dir) { anyhow::bail!( "Could not remove old symlink at {:?}: {}", shims_dir, diff --git a/tests/uninstall_test.rs b/tests/uninstall_test.rs index 33b68d6..e9a8869 100644 --- a/tests/uninstall_test.rs +++ b/tests/uninstall_test.rs @@ -7,11 +7,11 @@ mod uninstall { use crate::utils; fn setup_versions(temp_dir: &Path, versions: Vec<&str>) -> Result<()> { - for version_str in versions.to_owned().into_iter() { + for version_str in versions.iter().copied() { utils::install_mock_version(temp_dir, version_str)?; } - utils::create_shim(temp_dir, versions.get(0).unwrap()) + utils::create_shim(temp_dir, versions.first().unwrap()) } #[test] diff --git a/tests/utils.rs b/tests/utils.rs index 18ab991..37e0c27 100644 --- a/tests/utils.rs +++ b/tests/utils.rs @@ -57,6 +57,7 @@ pub fn install_mock_version(path: &Path, version_str: &str) -> Result<()> { Result::Ok(()) } +#[allow(dead_code)] #[cfg(windows)] pub fn create_shim(temp_dir: &Path, version_str: &str) -> Result<()> { symlink_dir( @@ -114,6 +115,7 @@ stderr output: Result::Ok(()) } +#[allow(dead_code)] pub fn assert_version_installed( temp_dir: &TempDir, version_str: &str, @@ -142,6 +144,7 @@ pub fn assert_version_installed( Result::Ok(()) } +#[allow(dead_code)] pub fn get_selected_version(temp_dir: &TempDir) -> Option { let symlink_path = temp_dir.child("shims");