Pārlūkot izejas kodu

avm: Handle empty .version file (#1407)

Tom Linton 3 gadi atpakaļ
vecāks
revīzija
afef73b864
4 mainītis faili ar 9 papildinājumiem un 4 dzēšanām
  1. 1 1
      Cargo.lock
  2. 1 1
      avm/Cargo.toml
  3. 6 1
      avm/src/lib.rs
  4. 1 1
      avm/src/main.rs

+ 1 - 1
Cargo.lock

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

+ 1 - 1
avm/Cargo.toml

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

+ 6 - 1
avm/src/lib.rs

@@ -98,6 +98,11 @@ pub fn install_version(version: &Version) -> Result<()> {
         &AVM_HOME.join("bin").join("anchor"),
         &AVM_HOME.join("bin").join("anchor"),
         &AVM_HOME.join("bin").join(format!("anchor-{}", version)),
         &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(())
     Ok(())
 }
 }
 
 
@@ -174,7 +179,7 @@ pub fn list_versions() -> Result<()> {
         if installed_versions.contains(v) {
         if installed_versions.contains(v) {
             flags.push("installed");
             flags.push("installed");
         }
         }
-        if current_version().unwrap() == v.clone() {
+        if current_version().is_ok() && current_version().unwrap() == v.clone() {
             flags.push("current");
             flags.push("current");
         }
         }
         if flags.is_empty() {
         if flags.is_empty() {

+ 1 - 1
avm/src/main.rs

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