Browse Source

remove avm use prompt, and insist on user installing a version if it's not yet installed (#1565)

Sven Dowideit 3 years ago
parent
commit
e567e14154
4 changed files with 57 additions and 38 deletions
  1. 1 0
      CHANGELOG.md
  2. 45 22
      Cargo.lock
  3. 1 2
      avm/Cargo.toml
  4. 10 14
      avm/src/lib.rs

+ 1 - 0
CHANGELOG.md

@@ -40,6 +40,7 @@ incremented for features.
 * lang: Remove space calculation using `#[derive(Default)]` ([#1519](https://github.com/project-serum/anchor/pull/1519)).
 * lang: Add support for logging expected and actual values and pubkeys. Add `require_eq` and `require_keys_eq` macros. Add default error code to `require` macro ([#1572](https://github.com/project-serum/anchor/pull/1572)).
 * lang: Add `system_program` CPI wrapper functions. Make `system_program` module public instead of re-exporting `system_program::System`([#1629](https://github.com/project-serum/anchor/pull/1629)).
+* cli: `avm use` no long prompts [y/n] if an install is needed first - it just tells the user to `avm install` ([#1565](https://github.com/project-serum/anchor/pull/1565))
 
 ## [0.22.1] - 2022-02-28
 

+ 45 - 22
Cargo.lock

@@ -320,8 +320,7 @@ dependencies = [
  "anyhow",
  "cfg-if 1.0.0",
  "clap 3.1.6",
- "dialoguer 0.9.0",
- "dirs 4.0.0",
+ "dirs 1.0.5",
  "once_cell",
  "reqwest",
  "semver 1.0.6",
@@ -386,6 +385,17 @@ version = "1.2.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
 
+[[package]]
+name = "blake2b_simd"
+version = "0.5.11"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "afa748e348ad3be8263be728124b24a24f268266f6f5d58af9d75f6a40b5c587"
+dependencies = [
+ "arrayref",
+ "arrayvec",
+ "constant_time_eq",
+]
+
 [[package]]
 name = "blake3"
 version = "0.3.8"
@@ -979,18 +989,6 @@ dependencies = [
  "tempfile",
 ]
 
-[[package]]
-name = "dialoguer"
-version = "0.9.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "61579ada4ec0c6031cfac3f86fdba0d195a7ebeb5e36693bd53cb5999a25beeb"
-dependencies = [
- "console 0.15.0",
- "lazy_static",
- "tempfile",
- "zeroize",
-]
-
 [[package]]
 name = "digest"
 version = "0.8.1"
@@ -1020,18 +1018,20 @@ dependencies = [
 
 [[package]]
 name = "dirs"
-version = "3.0.2"
+version = "1.0.5"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "30baa043103c9d0c2a57cf537cc2f35623889dc0d405e6c3cccfadbc81c71309"
+checksum = "3fd78930633bd1c6e35c4b42b1df7b0cbc6bc191146e512bb3bedf243fcc3901"
 dependencies = [
- "dirs-sys",
+ "libc",
+ "redox_users 0.3.5",
+ "winapi",
 ]
 
 [[package]]
 name = "dirs"
-version = "4.0.0"
+version = "3.0.2"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ca3aa72a6f96ea37bbc5aa912f6788242832f75369bdfdadcb0e38423f100059"
+checksum = "30baa043103c9d0c2a57cf537cc2f35623889dc0d405e6c3cccfadbc81c71309"
 dependencies = [
  "dirs-sys",
 ]
@@ -1053,7 +1053,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "03d86534ed367a67548dc68113a0f5db55432fdfbb6e6f9d77704397d95d5780"
 dependencies = [
  "libc",
- "redox_users",
+ "redox_users 0.4.0",
  "winapi",
 ]
 
@@ -1064,7 +1064,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d"
 dependencies = [
  "libc",
- "redox_users",
+ "redox_users 0.4.0",
  "winapi",
 ]
 
@@ -2505,6 +2505,17 @@ dependencies = [
  "bitflags",
 ]
 
+[[package]]
+name = "redox_users"
+version = "0.3.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "de0737333e7a9502c789a36d7c7fa6092a49895d4faa31ca5df163857ded2e9d"
+dependencies = [
+ "getrandom 0.1.16",
+ "redox_syscall 0.1.57",
+ "rust-argon2",
+]
+
 [[package]]
 name = "redox_users"
 version = "0.4.0"
@@ -2608,6 +2619,18 @@ dependencies = [
  "winapi",
 ]
 
+[[package]]
+name = "rust-argon2"
+version = "0.8.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4b18820d944b33caa75a71378964ac46f58517c92b6ae5f762636247c09e78fb"
+dependencies = [
+ "base64 0.13.0",
+ "blake2b_simd",
+ "constant_time_eq",
+ "crossbeam-utils 0.8.8",
+]
+
 [[package]]
 name = "rustc-demangle"
 version = "0.1.21"
@@ -3353,7 +3376,7 @@ checksum = "f009d977623835959420767d1d9db3b19b3cdac9ff57701f2449d453a2c2d7ee"
 dependencies = [
  "base32",
  "console 0.14.1",
- "dialoguer 0.6.2",
+ "dialoguer",
  "hidapi",
  "log",
  "num-derive",

+ 1 - 2
avm/Cargo.toml

@@ -16,8 +16,7 @@ path = "src/anchor/main.rs"
 clap = { version = "3.0.13", features = [ "derive" ]}
 cfg-if = "1.0.0"
 anyhow = "1.0.32"
-dialoguer = "0.9.0"
-dirs = "4.0"
+dirs = "1.0.5"
 semver = "1.0.4"
 serde = { version = "1.0.136", features = [ "derive" ]}
 serde_json = "1.0.78"

+ 10 - 14
avm/src/lib.rs

@@ -1,5 +1,4 @@
 use anyhow::{anyhow, Result};
-use dialoguer::Input;
 use once_cell::sync::Lazy;
 use reqwest::header::USER_AGENT;
 use semver::Version;
@@ -50,27 +49,24 @@ pub fn use_version(version: &Version) -> Result<()> {
     let installed_versions = read_installed_versions();
     // Make sure the requested version is installed
     if !installed_versions.contains(version) {
-        let input: String = Input::new()
-            .with_prompt(format!(
-                "anchor-cli {} is not installed, would you like to install it? (y/n)",
-                version
-            ))
-            .default("n".into())
-            .interact_text()?;
-        if matches!(input.as_str(), "y" | "yy" | "Y" | "yes" | "Yes") {
-            install_version(version)?;
-        } else {
+        if let Ok(current) = current_version() {
             println!(
                 "Version {} is not installed, staying on version {}.",
-                version,
-                current_version()?
+                version, current
             );
-            return Ok(());
+        } else {
+            println!("Version {} is not installed, no current version.", version);
         }
+
+        return Err(anyhow!(
+            "You need to run 'avm install {}' to install it before using it.",
+            version
+        ));
     }
 
     let mut current_version_file = fs::File::create(current_version_file_path().as_path())?;
     current_version_file.write_all(version.to_string().as_bytes())?;
+    println!("Now using anchor version {}.", current_version()?);
     Ok(())
 }