avm: Handle empty .version file (#1407)

This commit is contained in:
Tom Linton 2022-02-08 13:24:25 +13:00 committed by GitHub
parent a14a829a89
commit afef73b864
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 9 additions and 4 deletions

2
Cargo.lock generated
View File

@ -303,7 +303,7 @@ checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a"
[[package]]
name = "avm"
version = "0.1.0"
version = "0.20.1"
dependencies = [
"anyhow",
"cfg-if 1.0.0",

View File

@ -1,6 +1,6 @@
[package]
name = "avm"
version = "0.1.0"
version = "0.20.1"
edition = "2018"
[[bin]]

View File

@ -98,6 +98,11 @@ pub fn install_version(version: &Version) -> Result<()> {
&AVM_HOME.join("bin").join("anchor"),
&AVM_HOME.join("bin").join(format!("anchor-{}", version)),
)?;
// If .version file is empty or not parseable, write the newly installed version to it
if current_version().is_err() {
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(())
}
@ -174,7 +179,7 @@ pub fn list_versions() -> Result<()> {
if installed_versions.contains(v) {
flags.push("installed");
}
if current_version().unwrap() == v.clone() {
if current_version().is_ok() && current_version().unwrap() == v.clone() {
flags.push("current");
}
if flags.is_empty() {

View File

@ -5,7 +5,7 @@ use semver::Version;
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
#[derive(Parser)]
#[clap(name = "avm", about = "Anchor version manager")]
#[clap(name = "avm", about = "Anchor version manager", version)]
pub struct Cli {
#[clap(subcommand)]
command: Commands,