From 3f10ccfc85974087526d720403f564ea57d3d042 Mon Sep 17 00:00:00 2001 From: Italo Casas Date: Tue, 22 Mar 2022 15:51:36 -0400 Subject: [PATCH 1/5] Adding amv update and amv install improvements --- avm/src/lib.rs | 18 ++++++++++++++++++ avm/src/main.rs | 3 +++ 2 files changed, 21 insertions(+) diff --git a/avm/src/lib.rs b/avm/src/lib.rs index 63c21653ca..e88705e04d 100644 --- a/avm/src/lib.rs +++ b/avm/src/lib.rs @@ -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(()) +} + /// 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", @@ -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(()) } diff --git a/avm/src/main.rs b/avm/src/main.rs index 853bdad104..1184a9319a 100644 --- a/avm/src/main.rs +++ b/avm/src/main.rs @@ -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. @@ -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(), } } From 9db2c6bb96fbb3d74614ff219fb14b282450f751 Mon Sep 17 00:00:00 2001 From: Italo Casas Date: Tue, 22 Mar 2022 16:49:25 -0400 Subject: [PATCH 2/5] fixing comment --- avm/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/avm/src/lib.rs b/avm/src/lib.rs index e88705e04d..83fb0346cb 100644 --- a/avm/src/lib.rs +++ b/avm/src/lib.rs @@ -70,7 +70,7 @@ pub fn use_version(version: &Version) -> Result<()> { Ok(()) } -/// Update to latest stable version +/// Update to the latest version pub fn update() -> Result<()> { // Find last stable version let version = &get_latest_version(); From a37b796aa7834e74434ff95289a1e1ff460088da Mon Sep 17 00:00:00 2001 From: Italo Casas Date: Tue, 22 Mar 2022 16:58:05 -0400 Subject: [PATCH 3/5] adding avm install --foce flag --- avm/src/lib.rs | 6 +++--- avm/src/main.rs | 6 +++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/avm/src/lib.rs b/avm/src/lib.rs index 83fb0346cb..8913177493 100644 --- a/avm/src/lib.rs +++ b/avm/src/lib.rs @@ -75,15 +75,15 @@ pub fn update() -> Result<()> { // Find last stable version let version = &get_latest_version(); - install_version(version)?; + install_version(version, false)?; Ok(()) } /// 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) { + if installed_versions.contains(version) && !force { println!("Version {} is already installed", version); return Ok(()); } diff --git a/avm/src/main.rs b/avm/src/main.rs index 1184a9319a..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 { @@ -45,7 +49,7 @@ 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(), From 212224faabd3060340abcd17fa2bdfa93b0d5f7f Mon Sep 17 00:00:00 2001 From: Italo Casas Date: Tue, 22 Mar 2022 17:04:39 -0400 Subject: [PATCH 4/5] small update' --- avm/src/lib.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/avm/src/lib.rs b/avm/src/lib.rs index 8913177493..6dc484c21f 100644 --- a/avm/src/lib.rs +++ b/avm/src/lib.rs @@ -75,8 +75,7 @@ pub fn update() -> Result<()> { // Find last stable version let version = &get_latest_version(); - install_version(version, false)?; - Ok(()) + install_version(version, false) } /// Install a version of anchor-cli @@ -122,8 +121,7 @@ pub fn install_version(version: &Version, force: bool) -> Result<()> { current_version_file.write_all(version.to_string().as_bytes())?; } - use_version(version)?; - Ok(()) + use_version(version) } /// Remove an installed version of anchor-cli From fac4e788aa271ab323acb687ecaa27bfead76c7f Mon Sep 17 00:00:00 2001 From: Italo Casas Date: Tue, 22 Mar 2022 22:17:26 -0400 Subject: [PATCH 5/5] Updating CHANGELOG.md --- CHANGELOG.md | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b8581d85c5..252e5650fc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,11 +6,22 @@ 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)). + ## [0.23.0] - 2022-03-20 ### Features @@ -563,4 +574,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