Skip to content

Commit

Permalink
avm: Ask whether to install if the version is not installed with the …
Browse files Browse the repository at this point in the history
…`use` command (#3230)
  • Loading branch information
acheroncrypto committed Sep 6, 2024
1 parent 18e9134 commit 1c0b213
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ The minor version will be incremented upon a breaking change and the patch versi
- lang: Deprecate `#[interface]` attribute ([#3195](https://github.com/coral-xyz/anchor/pull/3195)).
- ts: Include unresolved accounts in the resolution error message ([#3207](https://github.com/coral-xyz/anchor/pull/3207)).
- lang: Add `LazyAccount` ([#3194](https://github.com/coral-xyz/anchor/pull/3194)).
- avm: Ask whether to install if the version is not installed with the `use` command ([#3230](https://github.com/coral-xyz/anchor/pull/3230)).

### Fixes

Expand Down
22 changes: 11 additions & 11 deletions avm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use reqwest::StatusCode;
use semver::{Prerelease, Version};
use serde::{de, Deserialize};
use std::fs;
use std::io::Write;
use std::io::{BufRead, Write};
use std::path::PathBuf;
use std::process::Stdio;

Expand Down Expand Up @@ -80,16 +80,16 @@ pub fn use_version(opt_version: Option<Version>) -> Result<()> {
// Make sure the requested version is installed
let installed_versions = read_installed_versions()?;
if !installed_versions.contains(&version) {
if let Ok(current) = current_version() {
println!("Version {version} is not installed, staying on version {current}.");
} else {
println!("Version {version} is not installed, no current version.");
}

return Err(anyhow!(
"You need to run 'avm install {}' to install it before using it.",
version
));
println!("Version {version} is not installed. Would you like to install? [y/n]");
let input = std::io::stdin()
.lock()
.lines()
.next()
.expect("Expected input")?;
match input.as_str() {
"y" | "yes" => return install_version(InstallTarget::Version(version), false),
_ => return Err(anyhow!("Installation rejected.")),
};
}

let mut current_version_file = fs::File::create(current_version_file_path())?;
Expand Down

0 comments on commit 1c0b213

Please sign in to comment.