Skip to content

Commit 2a32f0a

Browse files
authored
Fix Lint Warnings, Install Question Crash (#125)
1 parent 8c99c31 commit 2a32f0a

File tree

10 files changed

+26
-19
lines changed

10 files changed

+26
-19
lines changed

Taskfile.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ tasks:
66
cmds:
77
- cargo clippy
88
lint:fix:
9-
desc: Lint code
9+
desc: Lint code and fix problems with autofixes
1010
cmds:
1111
- cargo clippy --fix --allow-staged --allow-dirty
1212

@@ -25,6 +25,11 @@ tasks:
2525
cmds:
2626
- cargo test
2727

28+
run:
29+
desc: "Run the CLI with a debug build: task run -- <...args>"
30+
cmds:
31+
- cargo run
32+
2833
build:
2934
desc: Build debug artifacts
3035
sources:

src/archives.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,16 @@ pub fn extract_archive(bytes: Response, path: &Path) -> Result<()> {
2626

2727
for i in 0..archive.len() {
2828
let mut item = archive.by_index(i).unwrap();
29-
let file_path = item.sanitized_name();
29+
let file_path = item.mangled_name();
3030
let file_path = file_path.to_string_lossy();
3131

3232
let mut new_path = path.to_owned();
3333
if let Some(index) = file_path.find('\\') {
34-
new_path.push(file_path[index + 1..].to_owned());
34+
new_path.push(&file_path[index + 1..]);
3535
}
3636

3737
if item.is_dir() && !new_path.exists() {
38-
create_dir_all(new_path.to_owned())
38+
create_dir_all(&new_path)
3939
.unwrap_or_else(|_| panic!("Could not create new folder: {:?}", new_path));
4040
}
4141

@@ -52,7 +52,7 @@ pub fn extract_archive(bytes: Response, path: &Path) -> Result<()> {
5252
path.to_str()
5353
.unwrap()
5454
.strip_prefix("\\\\?\\")
55-
.unwrap_or(path.to_str().unwrap())
55+
.unwrap_or_else(|| path.to_str().unwrap())
5656
);
5757

5858
Result::Ok(())

src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ impl Config {
9494

9595
fn ensure_dir_exists(path: &Path) {
9696
if !path.exists() {
97-
create_dir_all(path.to_path_buf())
97+
create_dir_all(path)
9898
.unwrap_or_else(|err| panic!("Could not create {:?} - {}", path, err));
9999

100100
println!("Created nvm dir at {:?}", path);

src/node_version.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ impl OnlineNodeVersion {
7979

8080
let url = format!(
8181
"https://nodejs.org/dist/v{}/{}",
82-
self.version.to_string(),
82+
self.version,
8383
file_name
8484
);
8585

@@ -90,7 +90,7 @@ impl OnlineNodeVersion {
9090
fn get_file(&self) -> String {
9191
format!(
9292
"node-v{version}-win-{arch}.zip",
93-
version = self.version().to_string(),
93+
version = self.version(),
9494
arch = if cfg!(target_arch = "x86") {
9595
"x86"
9696
} else {

src/subcommand/install.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ pub struct InstallCommand {
2323
#[clap(validator = node_version::is_version_range)]
2424
pub version: Range,
2525
/// Switch to the new version after installing it
26-
#[clap(long, short)]
27-
pub switch: Option<bool>,
26+
#[clap(long, short, default_value("false"))]
27+
pub switch: bool,
2828
}
2929

3030
impl Action<InstallCommand> for InstallCommand {
@@ -55,12 +55,11 @@ impl Action<InstallCommand> for InstallCommand {
5555
)?;
5656

5757
if config.force
58-
|| (options.switch.is_none()
58+
|| (options.switch
5959
&& dialoguer::Confirm::new()
6060
.with_prompt(format!("Switch to {}?", version_to_install.to_string()))
6161
.default(true)
6262
.interact()?)
63-
|| options.switch.unwrap()
6463
{
6564
SwitchCommand::run(
6665
&config.with_force(),

src/subcommand/list.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ setting = AppSettings::ColoredHelp
4141
pub struct ListCommand {
4242
/// Only display installed versions
4343
#[clap(short, long)]
44-
pub installed: Option<bool>,
44+
pub installed: bool,
4545
/// Only display available versions
4646
#[clap(short, long, takes_value(false))]
47-
pub online: Option<bool>,
47+
pub online: bool,
4848
/// Filter by semantic versions.
4949
///
5050
/// `12`, `^10.9`, `>=8.10`, `>=8, <9`

src/subcommand/parse_version.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ impl Action<ParseVersionCommand> for ParseVersionCommand {
2525
"{:^pad$}\n{:^pad$}\n{}",
2626
options.version,
2727
"⬇",
28-
result.to_string(),
28+
result,
2929
pad = result.to_string().len()
3030
);
3131
Ok(())
@@ -34,7 +34,7 @@ impl Action<ParseVersionCommand> for ParseVersionCommand {
3434
println!(
3535
"Failed to parse `{}`: `{}`",
3636
options.version,
37-
err.to_string()
37+
err
3838
);
3939
Ok(())
4040
},

src/subcommand/switch.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ fn set_shims(config: &Config, version: &Version) -> Result<()> {
6464
}
6565

6666
if read_link(&shims_dir).is_ok() {
67-
if let Result::Err(err) = remove_dir(shims_dir.to_owned()) {
67+
if let Result::Err(err) = remove_dir(&shims_dir) {
6868
anyhow::bail!(
6969
"Could not remove old symlink at {:?}: {}",
7070
shims_dir,

tests/uninstall_test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ mod uninstall {
77
use crate::utils;
88

99
fn setup_versions(temp_dir: &Path, versions: Vec<&str>) -> Result<()> {
10-
for version_str in versions.to_owned().into_iter() {
10+
for version_str in versions.iter().copied() {
1111
utils::install_mock_version(temp_dir, version_str)?;
1212
}
1313

14-
utils::create_shim(temp_dir, versions.get(0).unwrap())
14+
utils::create_shim(temp_dir, versions.first().unwrap())
1515
}
1616

1717
#[test]

tests/utils.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ pub fn install_mock_version(path: &Path, version_str: &str) -> Result<()> {
5757
Result::Ok(())
5858
}
5959

60+
#[allow(dead_code)]
6061
#[cfg(windows)]
6162
pub fn create_shim(temp_dir: &Path, version_str: &str) -> Result<()> {
6263
symlink_dir(
@@ -114,6 +115,7 @@ stderr output:
114115
Result::Ok(())
115116
}
116117

118+
#[allow(dead_code)]
117119
pub fn assert_version_installed(
118120
temp_dir: &TempDir,
119121
version_str: &str,
@@ -142,6 +144,7 @@ pub fn assert_version_installed(
142144
Result::Ok(())
143145
}
144146

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

0 commit comments

Comments
 (0)