Skip to content

Commit

Permalink
fix: print correct version when using current subcommand
Browse files Browse the repository at this point in the history
  • Loading branch information
salamaashoush committed May 28, 2024
1 parent 2c27588 commit 21d6fc5
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 33 deletions.
5 changes: 5 additions & 0 deletions .changeset/breezy-pans-cheat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"pactup": patch
---

fix: print correct version when using current subcommand
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"url": "[email protected]:kadena-community/pactup.git"
},
"author": "Salama Ashoush <[email protected]>",
"packageManager": "[email protected].2",
"packageManager": "[email protected].3",
"license": "GPLv3",
"description": "Linter for the JavaScript Oxidation Compiler",
"keywords": [
Expand Down Expand Up @@ -44,7 +44,7 @@
},
"devDependencies": {
"@changesets/changelog-github": "0.5.0",
"@changesets/cli": "2.27.3",
"@changesets/cli": "2.27.4",
"@types/node": "^20.12.12",
"@types/shell-escape": "^0.2.3",
"chalk": "^5.3.0",
Expand All @@ -53,11 +53,11 @@
"execa": "9.1.0",
"lerna-changelog": "2.2.0",
"prettier": "3.2.5",
"pv": "1.0.1",
"shell-escape": "^0.2.0",
"svg-term-cli": "2.1.1",
"toml": "^3.0.0",
"tsx": "^4.11.0",
"typescript": "^5.4.5",
"pv": "1.0.1"
"typescript": "^5.4.5"
}
}
48 changes: 30 additions & 18 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 15 additions & 6 deletions src/commands/current.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,26 @@ use crate::config::PactupConfig;
use crate::current_version::{current_version, Error};

#[derive(clap::Parser, Debug)]
pub struct Current {}
pub struct Current {
#[clap(short, long)]
path: bool,
}

impl Command for Current {
type Error = Error;

fn apply(self, config: &PactupConfig) -> Result<(), Self::Error> {
let version_string = match current_version(config)? {
Some(ver) => ver.v_str(),
None => "none".into(),
};
println!("{version_string}");
let version = current_version(config)?;
if let Some(ver) = version {
if self.path {
println!("{}", ver.installation_path(config).display());
return Ok(());
}
println!("{}", ver.v_str());
} else {
println!("none");
}

Ok(())
}
}
6 changes: 1 addition & 5 deletions src/current_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,12 @@ use crate::version::Version;

pub fn current_version(config: &PactupConfig) -> Result<Option<Version>, Error> {
let multishell_path = config.multishell_path().ok_or(Error::EnvNotApplied)?;

if multishell_path.read_link().ok() == Some(system_version::path()) {
return Ok(Some(Version::Bypassed));
}

if let Ok(resolved_path) = std::fs::canonicalize(multishell_path) {
let installation_path = resolved_path
.parent()
.expect("multishell path can't be in the root");
let file_name = installation_path
let file_name = resolved_path
.file_name()
.expect("Can't get filename")
.to_str()
Expand Down

0 comments on commit 21d6fc5

Please sign in to comment.