diff --git a/CHANGELOG.md b/CHANGELOG.md index 4f84f7ca50..ae6c18f379 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,13 +6,21 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). **Note:** Version 0 of Semantic Versioning is handled differently from version 1 and above. -The minor version will be incremented upon a breaking change and the patch version will be -incremented for features. +The minor version will be incremented upon a breaking change and the patch version will be incremented for features. ## [Unreleased] ### Features +* avm: New `avm update` command to update the Anchor CLI to the latest version ([#1670](https://github.com/project-serum/anchor/pull/1670)). + +### Fixes + +* avm: `avm install` no longer downloads the version if already installed in the machine ([#1670](https://github.com/project-serum/anchor/pull/1670)). + +### Breaking + +* avm: `amv install` switches to the newly installed version after installation finishes ([#1670](https://github.com/project-serum/anchor/pull/1670)). * spl: Re-export the `spl_token` crate ([#1665](https://github.com/project-serum/anchor/pull/1665)). ## [0.23.0] - 2022-03-20 @@ -567,4 +575,4 @@ Initial release. * spl: `anchor-spl` crate providing CPI clients for Anchor programs. * client: `anchor-client` crate providing Rust clients for Anchor programs. * ts: `@project-serum/anchor` package for generating TypeScript clients. -* cli: Command line interface for managing Anchor programs. +* cli: Command line interface for managing Anchor programs. \ No newline at end of file diff --git a/avm/src/lib.rs b/avm/src/lib.rs index 63c21653ca..6dc484c21f 100644 --- a/avm/src/lib.rs +++ b/avm/src/lib.rs @@ -70,8 +70,23 @@ pub fn use_version(version: &Version) -> Result<()> { Ok(()) } +/// Update to the latest version +pub fn update() -> Result<()> { + // Find last stable version + let version = &get_latest_version(); + + install_version(version, false) +} + /// Install a version of anchor-cli -pub fn install_version(version: &Version) -> Result<()> { +pub fn install_version(version: &Version, force: bool) -> Result<()> { + // If version is already installed we ignore the request. + let installed_versions = read_installed_versions(); + if installed_versions.contains(version) && !force { + println!("Version {} is already installed", version); + return Ok(()); + } + let exit = std::process::Command::new("cargo") .args(&[ "install", @@ -105,7 +120,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())?; } - Ok(()) + + use_version(version) } /// Remove an installed version of anchor-cli diff --git a/avm/src/main.rs b/avm/src/main.rs index 853bdad104..97c53a0bcb 100644 --- a/avm/src/main.rs +++ b/avm/src/main.rs @@ -22,6 +22,10 @@ pub enum Commands { Install { #[clap(parse(try_from_str = parse_version))] version: Version, + #[clap(long)] + /// Flag to force installation even if the version + /// is already installed + force: bool, }, #[clap(about = "Uninstall a version of Anchor")] Uninstall { @@ -30,6 +34,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. @@ -43,9 +49,10 @@ fn parse_version(version: &str) -> Result { pub fn entry(opts: Cli) -> Result<()> { match opts.command { Commands::Use { version } => avm::use_version(&version), - Commands::Install { version } => avm::install_version(&version), + Commands::Install { version, force } => avm::install_version(&version, force), Commands::Uninstall { version } => avm::uninstall_version(&version), Commands::List {} => avm::list_versions(), + Commands::Update {} => avm::update(), } }