Cli refactor: rename wallet to cli (#6243)

* Rename Wallet structs to Cli

* Rename wallet to cli more broadly

* Update to cli/config.yml, and update docs
This commit is contained in:
Tyera Eulberg
2019-10-04 16:13:21 -06:00
committed by GitHub
parent 2e921437cd
commit 9c9754fa0f
13 changed files with 428 additions and 446 deletions

View File

@@ -1,10 +1,10 @@
use clap::{crate_description, crate_name, crate_version, Arg, ArgGroup, ArgMatches, SubCommand};
use console::style;
use solana_cli::{
cli::{app, parse_command, process_command, CliConfig, CliError},
config::{self, Config},
display::{println_name_value, println_name_value_or},
input_validators::is_url,
wallet::{app, parse_command, process_command, WalletConfig, WalletError},
};
use solana_sdk::signature::{read_keypair, KeypairUtil};
use std::error;
@@ -13,26 +13,22 @@ fn parse_settings(matches: &ArgMatches<'_>) -> Result<bool, Box<dyn error::Error
let parse_args = match matches.subcommand() {
("get", Some(subcommand_matches)) => {
if let Some(config_file) = matches.value_of("config_file") {
let default_wallet_config = WalletConfig::default();
let default_cli_config = CliConfig::default();
let config = Config::load(config_file).unwrap_or_default();
if let Some(field) = subcommand_matches.value_of("specific_setting") {
let (value, default_value) = match field {
"url" => (config.url, default_wallet_config.json_rpc_url),
"keypair" => (config.keypair, default_wallet_config.keypair_path),
"url" => (config.url, default_cli_config.json_rpc_url),
"keypair" => (config.keypair, default_cli_config.keypair_path),
_ => unreachable!(),
};
println_name_value_or(&format!("* {}:", field), &value, &default_value);
} else {
println_name_value("Wallet Config:", config_file);
println_name_value_or(
"* url:",
&config.url,
&default_wallet_config.json_rpc_url,
);
println_name_value_or("* url:", &config.url, &default_cli_config.json_rpc_url);
println_name_value_or(
"* keypair:",
&config.keypair,
&default_wallet_config.keypair_path,
&default_cli_config.keypair_path,
);
}
} else {
@@ -69,7 +65,7 @@ fn parse_settings(matches: &ArgMatches<'_>) -> Result<bool, Box<dyn error::Error
Ok(parse_args)
}
pub fn parse_args(matches: &ArgMatches<'_>) -> Result<WalletConfig, Box<dyn error::Error>> {
pub fn parse_args(matches: &ArgMatches<'_>) -> Result<CliConfig, Box<dyn error::Error>> {
let config = if let Some(config_file) = matches.value_of("config_file") {
Config::load(config_file).unwrap_or_default()
} else {
@@ -80,7 +76,7 @@ pub fn parse_args(matches: &ArgMatches<'_>) -> Result<WalletConfig, Box<dyn erro
} else if config.url != "" {
config.url
} else {
let default = WalletConfig::default();
let default = CliConfig::default();
default.json_rpc_url
};
@@ -89,9 +85,9 @@ pub fn parse_args(matches: &ArgMatches<'_>) -> Result<WalletConfig, Box<dyn erro
} else if config.keypair != "" {
config.keypair
} else {
let default = WalletConfig::default();
let default = CliConfig::default();
if !std::path::Path::new(&default.keypair_path).exists() {
return Err(WalletError::KeypairFileNotFound(
return Err(CliError::KeypairFileNotFound(
"Generate a new keypair with `solana-keygen new`".to_string(),
)
.into());
@@ -99,7 +95,7 @@ pub fn parse_args(matches: &ArgMatches<'_>) -> Result<WalletConfig, Box<dyn erro
default.keypair_path
};
let keypair = read_keypair(&keypair_path).or_else(|err| {
Err(WalletError::BadParameter(format!(
Err(CliError::BadParameter(format!(
"{}: Unable to open keypair file: {}",
err, keypair_path
)))
@@ -107,7 +103,7 @@ pub fn parse_args(matches: &ArgMatches<'_>) -> Result<WalletConfig, Box<dyn erro
let command = parse_command(&keypair.pubkey(), &matches)?;
Ok(WalletConfig {
Ok(CliConfig {
command,
json_rpc_url,
keypair,
@@ -154,7 +150,7 @@ fn main() -> Result<(), Box<dyn error::Error>> {
)
.subcommand(
SubCommand::with_name("get")
.about("Get wallet config settings")
.about("Get cli config settings")
.arg(
Arg::with_name("specific_setting")
.index(1)
@@ -166,7 +162,7 @@ fn main() -> Result<(), Box<dyn error::Error>> {
)
.subcommand(
SubCommand::with_name("set")
.about("Set a wallet config setting")
.about("Set a cli config setting")
.group(
ArgGroup::with_name("config_settings")
.args(&["json_rpc_url", "keypair"])