Skip to content

Commit

Permalink
fix(cli.rs/info): don't show outdated text for latest versions (#3829)
Browse files Browse the repository at this point in the history
  • Loading branch information
amrbashir authored Apr 1, 2022
1 parent 7c7d854 commit 73a4b74
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
6 changes: 6 additions & 0 deletions .changes/cli-info-outdated.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"cli.rs": "patch"
"cli.js": "patch"
---

Fix `info` command showing outdated text for latest versions.
31 changes: 16 additions & 15 deletions tooling/cli/src/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,10 +441,7 @@ fn crate_version(
}

fn indent(spaces: usize) {
print!(
"{}",
vec![0; spaces].iter().map(|_| " ").collect::<String>()
);
print!("{}", " ".repeat(spaces));
}

struct Section(&'static str);
Expand All @@ -460,7 +457,7 @@ struct VersionBlock {
version: String,
target_version: String,
indentation: usize,
skip_update: bool,
skip_update_check: bool,
}

impl VersionBlock {
Expand All @@ -470,12 +467,12 @@ impl VersionBlock {
version: version.into(),
target_version: "".into(),
indentation: 2,
skip_update: false,
skip_update_check: false,
}
}

fn skip_update(mut self) -> Self {
self.skip_update = true;
fn skip_update_check(mut self) -> Self {
self.skip_update_check = true;
self
}

Expand All @@ -497,12 +494,16 @@ impl VersionBlock {
self.version.clone()
}
);
if !self.target_version.is_empty() && !self.skip_update {
print!(
"({}, latest: {})",
"outdated".red(),
self.target_version.green()
);
if !self.target_version.is_empty() && !self.skip_update_check {
let version = semver::Version::parse(self.version.as_str()).unwrap();
let target_version = semver::Version::parse(self.target_version.as_str()).unwrap();
if version < target_version {
print!(
"({}, latest: {})",
"outdated".red(),
self.target_version.green()
);
}
}
println!();
}
Expand Down Expand Up @@ -592,7 +593,7 @@ pub fn command(_options: Options) -> Result<()> {
.collect::<String>(),
)
.target_version(metadata.js_cli.node.replace(">= ", ""))
.skip_update()
.skip_update_check()
.display();

VersionBlock::new(
Expand Down

0 comments on commit 73a4b74

Please sign in to comment.