From c89b35545cae1c37ebd1988410315e076e7cba60 Mon Sep 17 00:00:00 2001 From: Michael Vines Date: Fri, 14 Feb 2020 20:35:40 -0700 Subject: [PATCH] install: support vX.Y.Z in addition to X.Y.Z (#8297) automerge (cherry picked from commit 335675c51c4661eee4cd6cc4c9ced18796103ae7) --- Cargo.lock | 2 +- clap-utils/Cargo.toml | 1 - clap-utils/src/input_validators.rs | 14 ------ install/Cargo.toml | 1 + install/src/lib.rs | 73 ++++++++++++++++++++---------- 5 files changed, 51 insertions(+), 40 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ccfd7e6b17..bfd0639758 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3663,7 +3663,6 @@ dependencies = [ "chrono 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)", "rpassword 4.0.5 (registry+https://github.com/rust-lang/crates.io-index)", - "semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "solana-remote-wallet 0.23.5", "solana-sdk 0.23.5", "tiny-bip39 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3960,6 +3959,7 @@ dependencies = [ "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "nix 0.16.1 (registry+https://github.com/rust-lang/crates.io-index)", "reqwest 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", + "semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)", "serde_yaml 0.8.11 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/clap-utils/Cargo.toml b/clap-utils/Cargo.toml index 9e982b0dc6..bba64bdc56 100644 --- a/clap-utils/Cargo.toml +++ b/clap-utils/Cargo.toml @@ -11,7 +11,6 @@ edition = "2018" [dependencies] clap = "2.33.0" rpassword = "4.0" -semver = "0.9.0" solana-remote-wallet = { path = "../remote-wallet", version = "0.23.5" } solana-sdk = { path = "../sdk", version = "0.23.5" } tiny-bip39 = "0.7.0" diff --git a/clap-utils/src/input_validators.rs b/clap-utils/src/input_validators.rs index 2b49c4f429..6c68278418 100644 --- a/clap-utils/src/input_validators.rs +++ b/clap-utils/src/input_validators.rs @@ -86,20 +86,6 @@ pub fn is_url(string: String) -> Result<(), String> { } } -pub fn is_semver(semver: &str) -> Result<(), String> { - match semver::Version::parse(&semver) { - Ok(_) => Ok(()), - Err(err) => Err(format!("{:?}", err)), - } -} - -pub fn is_release_channel(channel: &str) -> Result<(), String> { - match channel { - "edge" | "beta" | "stable" => Ok(()), - _ => Err(format!("Invalid release channel {}", channel)), - } -} - pub fn is_port(port: String) -> Result<(), String> { port.parse::() .map(|_| ()) diff --git a/install/Cargo.toml b/install/Cargo.toml index bb7fac8cc4..b2bd4dca5b 100644 --- a/install/Cargo.toml +++ b/install/Cargo.toml @@ -31,6 +31,7 @@ solana-client = { path = "../client", version = "0.23.5" } solana-config-program = { path = "../programs/config", version = "0.23.5" } solana-logger = { path = "../logger", version = "0.23.5" } solana-sdk = { path = "../sdk", version = "0.23.5" } +semver = "0.9.0" tar = "0.4.26" tempdir = "0.3.7" url = "2.1.1" diff --git a/install/src/lib.rs b/install/src/lib.rs index 517cf0868a..ac27f2243f 100644 --- a/install/src/lib.rs +++ b/install/src/lib.rs @@ -1,8 +1,8 @@ #[macro_use] extern crate lazy_static; -use clap::{crate_description, crate_name, App, AppSettings, Arg, SubCommand}; -use solana_clap_utils::input_validators::{is_pubkey, is_release_channel, is_semver, is_url}; +use clap::{crate_description, crate_name, App, AppSettings, Arg, ArgMatches, SubCommand}; +use solana_clap_utils::input_validators::{is_pubkey, is_url}; use solana_sdk::pubkey::Pubkey; mod build_env; @@ -12,6 +12,47 @@ mod defaults; mod stop_process; mod update_manifest; +pub fn is_semver(semver: &str) -> Result<(), String> { + match semver::Version::parse(&semver) { + Ok(_) => Ok(()), + Err(err) => Err(format!("{:?}", err)), + } +} + +pub fn is_release_channel(channel: &str) -> Result<(), String> { + match channel { + "edge" | "beta" | "stable" => Ok(()), + _ => Err(format!("Invalid release channel {}", channel)), + } +} + +pub fn is_explicit_release(string: String) -> Result<(), String> { + if string.starts_with('v') && is_semver(string.split_at(1).1).is_ok() { + return Ok(()); + } + is_semver(&string).or_else(|_| is_release_channel(&string)) +} + +pub fn explicit_release_of( + matches: &ArgMatches<'_>, + name: &str, +) -> Option { + matches + .value_of(name) + .map(ToString::to_string) + .map(|explicit_release| { + if explicit_release.starts_with('v') + && is_semver(explicit_release.split_at(1).1).is_ok() + { + config::ExplicitRelease::Semver(explicit_release.split_at(1).1.to_string()) + } else if is_semver(&explicit_release).is_ok() { + config::ExplicitRelease::Semver(explicit_release) + } else { + config::ExplicitRelease::Channel(explicit_release) + } + }) +} + pub fn main() -> Result<(), String> { solana_logger::setup(); @@ -84,7 +125,7 @@ pub fn main() -> Result<(), String> { .value_name("release") .index(1) .conflicts_with_all(&["json_rpc_url", "update_manifest_pubkey"]) - .validator(|string| is_semver(&string).or_else(|_| is_release_channel(&string))) + .validator(is_explicit_release) .help("The exact version to install. Either a semver or release channel name"), ), ) @@ -179,9 +220,7 @@ pub fn main() -> Result<(), String> { .unwrap(); let data_dir = matches.value_of("data_dir").unwrap(); let no_modify_path = matches.is_present("no_modify_path"); - let explicit_release = matches - .value_of("explicit_release") - .map(ToString::to_string); + let explicit_release = explicit_release_of(&matches, "explicit_release"); command::init( config_file, @@ -189,13 +228,7 @@ pub fn main() -> Result<(), String> { json_rpc_url, &update_manifest_pubkey, no_modify_path, - explicit_release.map(|explicit_release| { - if is_semver(&explicit_release).is_ok() { - config::ExplicitRelease::Semver(explicit_release) - } else { - config::ExplicitRelease::Channel(explicit_release) - } - }), + explicit_release, ) } ("info", Some(matches)) => { @@ -295,7 +328,7 @@ pub fn main_init() -> Result<(), String> { .value_name("release") .index(1) .conflicts_with_all(&["json_rpc_url", "update_manifest_pubkey"]) - .validator(|string| is_semver(&string).or_else(|_| is_release_channel(&string))) + .validator(is_explicit_release) .help("The exact version to install. Updates will not be available if this argument is used"), ) .get_matches(); @@ -310,9 +343,7 @@ pub fn main_init() -> Result<(), String> { .unwrap(); let data_dir = matches.value_of("data_dir").unwrap(); let no_modify_path = matches.is_present("no_modify_path"); - let explicit_release = matches - .value_of("explicit_release") - .map(ToString::to_string); + let explicit_release = explicit_release_of(&matches, "explicit_release"); command::init( config_file, @@ -320,12 +351,6 @@ pub fn main_init() -> Result<(), String> { json_rpc_url, &update_manifest_pubkey, no_modify_path, - explicit_release.map(|explicit_release| { - if is_semver(&explicit_release).is_ok() { - config::ExplicitRelease::Semver(explicit_release) - } else { - config::ExplicitRelease::Channel(explicit_release) - } - }), + explicit_release, ) }