Skip to content

Commit

Permalink
install: support vX.Y.Z in addition to X.Y.Z (#8297)
Browse files Browse the repository at this point in the history
automerge

(cherry picked from commit 335675c)
  • Loading branch information
mvines committed Feb 15, 2020
1 parent 370716e commit c89b355
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 40 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion clap-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
14 changes: 0 additions & 14 deletions clap-utils/src/input_validators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(|_| ())
Expand Down
1 change: 1 addition & 0 deletions install/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
73 changes: 49 additions & 24 deletions install/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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();

Expand Down Expand Up @@ -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"),
),
)
Expand Down Expand Up @@ -179,23 +220,15 @@ 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,
data_dir,
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)) => {
Expand Down Expand Up @@ -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();
Expand All @@ -310,22 +343,14 @@ 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,
data_dir,
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,
)
}

0 comments on commit c89b355

Please sign in to comment.