Skip to content

Commit

Permalink
feat(svm): add which subcommand (#137)
Browse files Browse the repository at this point in the history
```
svm which 0.8.25
/Users/user/Library/Application Support/svm/0.8.25/solc-0.8.25
```
  • Loading branch information
DaniPopes authored Aug 19, 2024
1 parent bbeb352 commit 63dec8e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
3 changes: 3 additions & 0 deletions crates/svm-rs/src/bin/svm-bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ mod print;
mod remove;
mod r#use;
mod utils;
mod which;

/// Solc version manager.
#[derive(Debug, Parser)]
Expand All @@ -28,6 +29,7 @@ enum Svm {
List(list::ListCmd),
Install(install::InstallCmd),
Use(r#use::UseCmd),
Which(which::WhichCmd),
Remove(remove::RemoveCmd),
}

Expand All @@ -41,6 +43,7 @@ async fn main() -> anyhow::Result<()> {
Svm::List(cmd) => cmd.run().await?,
Svm::Install(cmd) => cmd.run().await?,
Svm::Use(cmd) => cmd.run().await?,
Svm::Which(cmd) => cmd.run()?,
Svm::Remove(cmd) => cmd.run().await?,
}

Expand Down
22 changes: 22 additions & 0 deletions crates/svm-rs/src/bin/svm-bin/which.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use clap::Parser;
use semver::Version;

/// Display which binary will be run for a given version.
#[derive(Debug, Parser)]
pub struct WhichCmd {
/// The version to check.
version: Version,
}

impl WhichCmd {
pub fn run(self) -> anyhow::Result<()> {
let Self { version } = self;
let bin = svm::version_binary(&version.to_string());
if bin.exists() {
println!("{}", bin.display());
} else {
return Err(anyhow::anyhow!("version {version} not installed"));
}
Ok(())
}
}

0 comments on commit 63dec8e

Please sign in to comment.