install: support vX.Y.Z in addition to X.Y.Z (#8297)

automerge
This commit is contained in:
Michael Vines 2020-02-14 20:35:40 -07:00 committed by GitHub
parent 1bf2285fa2
commit 335675c51c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 51 additions and 40 deletions

2
Cargo.lock generated
View File

@ -3726,7 +3726,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.24.0",
"solana-sdk 0.24.0",
"tiny-bip39 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -4019,6 +4018,7 @@ dependencies = [
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"nix 0.17.0 (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)",

View File

@ -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.24.0" }
solana-sdk = { path = "../sdk", version = "0.24.0" }
tiny-bip39 = "0.7.0"

View File

@ -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::<u16>()
.map(|_| ())

View File

@ -29,6 +29,7 @@ solana-client = { path = "../client", version = "0.24.0" }
solana-config-program = { path = "../programs/config", version = "0.24.0" }
solana-logger = { path = "../logger", version = "0.24.0" }
solana-sdk = { path = "../sdk", version = "0.24.0" }
semver = "0.9.0"
tar = "0.4.26"
tempdir = "0.3.7"
url = "2.1.1"

View File

@ -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<config::ExplicitRelease> {
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,
)
}