Skip to content

Commit

Permalink
Consider config in check_for_usb (solana-labs#9555)
Browse files Browse the repository at this point in the history
  • Loading branch information
CriesofCarrots authored Apr 17, 2020
1 parent 9bba27a commit a9c38fb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
20 changes: 14 additions & 6 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use solana_cli_config::{Config, CONFIG_FILE};
use solana_remote_wallet::remote_wallet::{maybe_wallet_manager, RemoteWalletManager};
use std::{error, sync::Arc};

fn parse_settings(matches: &ArgMatches<'_>) -> Result<bool, Box<dyn error::Error>> {
fn parse_settings(matches: &ArgMatches<'_>) -> Result<Option<bool>, Box<dyn error::Error>> {
let parse_args = match matches.subcommand() {
("config", Some(matches)) => match matches.subcommand() {
("get", Some(subcommand_matches)) => {
Expand Down Expand Up @@ -54,7 +54,7 @@ fn parse_settings(matches: &ArgMatches<'_>) -> Result<bool, Box<dyn error::Error
style("No config file found.").bold()
);
}
false
None
}
("set", Some(subcommand_matches)) => {
if let Some(config_file) = matches.value_of("config_file") {
Expand Down Expand Up @@ -94,11 +94,19 @@ fn parse_settings(matches: &ArgMatches<'_>) -> Result<bool, Box<dyn error::Error
style("No config file found.").bold()
);
}
false
None
}
_ => unreachable!(),
},
_ => true,
_ => {
let need_wallet_manager = if let Some(config_file) = matches.value_of("config_file") {
let config = Config::load(config_file).unwrap_or_default();
check_for_usb([config.keypair_path].iter())
} else {
false
};
Some(need_wallet_manager)
}
};
Ok(parse_args)
}
Expand Down Expand Up @@ -262,8 +270,8 @@ fn do_main(
matches: &ArgMatches<'_>,
need_wallet_manager: bool,
) -> Result<(), Box<dyn error::Error>> {
if parse_settings(&matches)? {
let wallet_manager = if need_wallet_manager {
if let Some(config_need_wallet_manager) = parse_settings(&matches)? {
let wallet_manager = if need_wallet_manager || config_need_wallet_manager {
maybe_wallet_manager()?
} else {
None
Expand Down
11 changes: 6 additions & 5 deletions keygen/src/keygen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,11 +407,12 @@ fn do_main(matches: &ArgMatches<'_>) -> Result<(), Box<dyn error::Error>> {
Config::default()
};

let wallet_manager = if check_for_usb(std::env::args()) {
maybe_wallet_manager()?
} else {
None
};
let wallet_manager =
if check_for_usb(std::env::args()) || check_for_usb([config.keypair_path.clone()].iter()) {
maybe_wallet_manager()?
} else {
None
};

match matches.subcommand() {
("pubkey", Some(matches)) => {
Expand Down

0 comments on commit a9c38fb

Please sign in to comment.