Simplier and cleaner implementation of #1468 (#1471)

* Simplier and cleaner implementation of #1468

* move AppInfo into base_path

* default to executable_name rather than pretty visible name
This commit is contained in:
Benjamin Kampmann
2019-01-17 22:26:58 +01:00
committed by Gav Wood
parent a7a0121b09
commit d4eb3872a0
5 changed files with 19 additions and 24 deletions
-1
View File
@@ -1712,7 +1712,6 @@ dependencies = [
name = "node-cli"
version = "0.1.0"
dependencies = [
"app_dirs 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)",
"exit-future 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
"futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)",
+13 -9
View File
@@ -85,6 +85,8 @@ use futures::Future;
/// Executable version. Used to pass version information from the root crate.
pub struct VersionInfo {
/// Implemtation name.
pub name: &'static str,
/// Implementation version.
pub version: &'static str,
/// SCM Commit hash.
@@ -130,13 +132,16 @@ fn load_spec<F, G>(matches: &clap::ArgMatches, factory: F) -> Result<ChainSpec<G
Ok(spec)
}
fn base_path(matches: &clap::ArgMatches, app_info: &AppInfo) -> PathBuf {
fn base_path(matches: &clap::ArgMatches, version: &VersionInfo) -> PathBuf {
matches.value_of("base_path")
.map(|x| Path::new(x).to_owned())
.unwrap_or_else(||
app_dirs::get_app_root(
AppDataType::UserData,
app_info,
&AppInfo {
name: version.executable_name,
author: version.author
}
).expect("app directories exist on all supported platforms; qed")
)
}
@@ -193,10 +198,9 @@ where
/// Parse clap::Matches into config and chain specification
pub fn parse_matches<'a, F, S>(
spec_factory: S,
version: VersionInfo,
version: &VersionInfo,
impl_name: &'static str,
matches: &clap::ArgMatches<'a>,
app_info: &AppInfo,
) -> error::Result<(ChainSpec<<F as service::ServiceFactory>::Genesis>, FactoryFullConfiguration<F>)>
where
F: ServiceFactory,
@@ -226,7 +230,7 @@ where
)
}
let base_path = base_path(&matches, &app_info);
let base_path = base_path(&matches, version);
config.keystore_path = matches.value_of("keystore")
.map(|x| Path::new(x).to_owned())
@@ -344,7 +348,7 @@ where
fn get_db_path_for_subcommand(
main_cmd: &clap::ArgMatches,
sub_cmd: &clap::ArgMatches,
app_info: &AppInfo,
version: &VersionInfo,
) -> error::Result<PathBuf> {
if main_cmd.is_present("chain") && sub_cmd.is_present("chain") {
bail!(create_input_err("`--chain` option is present two times"));
@@ -375,9 +379,9 @@ fn get_db_path_for_subcommand(
}
let base_path = if sub_cmd.is_present("base_path") {
base_path(sub_cmd, app_info)
base_path(sub_cmd, version)
} else {
base_path(main_cmd, app_info)
base_path(main_cmd, version)
};
Ok(db_path(&base_path, &spec_id))
@@ -397,7 +401,7 @@ pub fn execute_default<'a, F, E>(
exit: E,
matches: &clap::ArgMatches<'a>,
config: &FactoryFullConfiguration<F>,
app_info: &AppInfo,
app_info: &VersionInfo,
) -> error::Result<Action<E>>
where
E: IntoExit,
-1
View File
@@ -13,7 +13,6 @@ exit-future = "0.1"
substrate-cli = { path = "../../core/cli" }
parity-codec = { version = "2.2" }
slog = "^2"
app_dirs = "1.2"
sr-io = { path = "../../core/sr-io" }
substrate-client = { path = "../../core/client" }
substrate-primitives = { path = "../../core/primitives" }
+4 -12
View File
@@ -20,7 +20,6 @@
#![warn(unused_extern_crates)]
extern crate tokio;
extern crate app_dirs;
extern crate substrate_cli as cli;
extern crate substrate_primitives as primitives;
@@ -58,13 +57,6 @@ use substrate_service::{ServiceFactory, Roles as ServiceRoles};
use params::{Params as NodeParams};
use structopt::StructOpt;
use std::ops::Deref;
use app_dirs::AppInfo;
const APP_INFO: AppInfo = AppInfo {
name: "Substrate Node",
author: "Parity Technologies"
};
/// The chain specification option.
#[derive(Clone, Debug)]
@@ -130,15 +122,15 @@ pub fn run<I, T, E>(args: I, exit: E, version: cli::VersionInfo) -> error::Resul
};
let (spec, config) = cli::parse_matches::<service::Factory, _>(
load_spec, version, "substrate-node", &matches, &APP_INFO
load_spec, &version, "substrate-node", &matches
)?;
match cli::execute_default::<service::Factory, _>(spec, exit, &matches, &config, &APP_INFO)? {
match cli::execute_default::<service::Factory, _>(spec, exit, &matches, &config, &version)? {
cli::Action::ExecutedInternally => (),
cli::Action::RunService(exit) => {
info!("{}", APP_INFO.name);
info!("{}", version.name);
info!(" version {}", config.full_version());
info!(" by {}, 2017, 2018", APP_INFO.author);
info!(" by {}, 2017, 2018", version.author);
info!("Chain specification: {}", config.chain_spec.name());
info!("Node name: {}", config.name);
info!("Roles: {:?}", config.roles);
+2 -1
View File
@@ -54,10 +54,11 @@ quick_main!(run);
fn run() -> cli::error::Result<()> {
let version = VersionInfo {
name: "Substrate Node",
commit: env!("VERGEN_SHA_SHORT"),
version: env!("CARGO_PKG_VERSION"),
executable_name: "substrate",
author: "Parity Team <admin@parity.io>",
author: "Parity Technologies <admin@parity.io>",
description: "Generic substrate node",
};
cli::run(::std::env::args(), Exit, version)