Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

amv improvements #1670

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 18 additions & 0 deletions avm/src/lib.rs
Expand Up @@ -70,8 +70,24 @@ pub fn use_version(version: &Version) -> Result<()> {
Ok(())
}

/// Update to latest stable version
pub fn update() -> Result<()> {
// Find last stable version
let version = &get_latest_version();

install_version(version)?;
Ok(())
italoacasas marked this conversation as resolved.
Show resolved Hide resolved
}

/// Install a version of anchor-cli
pub fn install_version(version: &Version) -> Result<()> {
// If version is already installed we ignore the request.
let installed_versions = read_installed_versions();
if installed_versions.contains(version) {
println!("Version {} is already installed", version);
return Ok(());
}

let exit = std::process::Command::new("cargo")
.args(&[
"install",
Expand Down Expand Up @@ -105,6 +121,8 @@ pub fn install_version(version: &Version) -> Result<()> {
let mut current_version_file = fs::File::create(current_version_file_path().as_path())?;
current_version_file.write_all(version.to_string().as_bytes())?;
}

use_version(version)?;
Ok(())
}

Expand Down
3 changes: 3 additions & 0 deletions avm/src/main.rs
Expand Up @@ -30,6 +30,8 @@ pub enum Commands {
},
#[clap(about = "List available versions of Anchor")]
List {},
#[clap(about = "Update to the latest Anchor version")]
Update {},
}

// If `latest` is passed use the latest available version.
Expand All @@ -46,6 +48,7 @@ pub fn entry(opts: Cli) -> Result<()> {
Commands::Install { version } => avm::install_version(&version),
Commands::Uninstall { version } => avm::uninstall_version(&version),
Commands::List {} => avm::list_versions(),
Commands::Update {} => avm::update(),
}
}

Expand Down