Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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:
Expand Down
8 changes: 4 additions & 4 deletions src/archives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand All @@ -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(())
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/node_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl OnlineNodeVersion {

let url = format!(
"https://nodejs.org/dist/v{}/{}",
self.version.to_string(),
self.version,
file_name
);

Expand All @@ -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 {
Expand Down
7 changes: 3 additions & 4 deletions src/subcommand/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool>,
#[clap(long, short, default_value("false"))]
pub switch: bool,
}

impl Action<InstallCommand> for InstallCommand {
Expand Down Expand Up @@ -55,12 +55,11 @@ impl Action<InstallCommand> 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(),
Expand Down
4 changes: 2 additions & 2 deletions src/subcommand/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ setting = AppSettings::ColoredHelp
pub struct ListCommand {
/// Only display installed versions
#[clap(short, long)]
pub installed: Option<bool>,
pub installed: bool,
/// Only display available versions
#[clap(short, long, takes_value(false))]
pub online: Option<bool>,
pub online: bool,
/// Filter by semantic versions.
///
/// `12`, `^10.9`, `>=8.10`, `>=8, <9`
Expand Down
4 changes: 2 additions & 2 deletions src/subcommand/parse_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl Action<ParseVersionCommand> for ParseVersionCommand {
"{:^pad$}\n{:^pad$}\n{}",
options.version,
"⬇",
result.to_string(),
result,
pad = result.to_string().len()
);
Ok(())
Expand All @@ -34,7 +34,7 @@ impl Action<ParseVersionCommand> for ParseVersionCommand {
println!(
"Failed to parse `{}`: `{}`",
options.version,
err.to_string()
err
);
Ok(())
},
Expand Down
2 changes: 1 addition & 1 deletion src/subcommand/switch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions tests/uninstall_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
3 changes: 3 additions & 0 deletions tests/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -114,6 +115,7 @@ stderr output:
Result::Ok(())
}

#[allow(dead_code)]
pub fn assert_version_installed(
temp_dir: &TempDir,
version_str: &str,
Expand Down Expand Up @@ -142,6 +144,7 @@ pub fn assert_version_installed(
Result::Ok(())
}

#[allow(dead_code)]
pub fn get_selected_version(temp_dir: &TempDir) -> Option<String> {
let symlink_path = temp_dir.child("shims");

Expand Down