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 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happened here? I saw that in a different PR too 🤔

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably just a github bug?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Visual Studio Code doing weird stuff when I saved the document 😵‍💫

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh maybe a different os line break?

Copy link
Contributor Author

@italoacasas italoacasas Mar 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe, not sure honestly, but I think it is more than just that. For example, if I use VSCode, when I save, all the * get replaced by -.

20 changes: 18 additions & 2 deletions avm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion avm/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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.
Expand All @@ -43,9 +49,10 @@ fn parse_version(version: &str) -> Result<Version, Error> {
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(),
}
}

Expand Down