mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-21 01:41:03 +00:00
Update SubstrateCli to return String (#6550)
* Update SubstrateCli to return String * Add default implementation for executable_name() * Use display instead of PathBuf * Get file_name in default impl of executable_name * Remove String::from and use .into() * Use default impl for executable_name() * Use .as_str() and remove useless .to_string() * Update only sp-io when running companion build * Remove unneeded update of sp-io in CI Co-authored-by: Cecile Tonglet <cecile@parity.io>
This commit is contained in:
@@ -413,7 +413,7 @@ pub trait CliConfiguration: Sized {
|
||||
let chain_spec = cli.load_spec(chain_id.as_str())?;
|
||||
let base_path = self
|
||||
.base_path()?
|
||||
.unwrap_or_else(|| BasePath::from_project("", "", C::executable_name()));
|
||||
.unwrap_or_else(|| BasePath::from_project("", "", &C::executable_name()));
|
||||
let config_dir = base_path
|
||||
.path()
|
||||
.to_path_buf()
|
||||
@@ -498,7 +498,7 @@ pub trait CliConfiguration: Sized {
|
||||
fn init<C: SubstrateCli>(&self) -> Result<()> {
|
||||
let logger_pattern = self.log_filters()?;
|
||||
|
||||
sp_panic_handler::set(C::support_url(), C::impl_version());
|
||||
sp_panic_handler::set(&C::support_url(), &C::impl_version());
|
||||
|
||||
fdlimit::raise_fd_limit();
|
||||
init_logger(&logger_pattern);
|
||||
|
||||
@@ -57,25 +57,33 @@ use structopt::{
|
||||
/// its own implementation that will fill the necessary field based on the trait's functions.
|
||||
pub trait SubstrateCli: Sized {
|
||||
/// Implementation name.
|
||||
fn impl_name() -> &'static str;
|
||||
fn impl_name() -> String;
|
||||
|
||||
/// Implementation version.
|
||||
///
|
||||
/// By default this will look like this: 2.0.0-b950f731c-x86_64-linux-gnu where the hash is the
|
||||
/// short commit hash of the commit of in the Git repository.
|
||||
fn impl_version() -> &'static str;
|
||||
fn impl_version() -> String;
|
||||
|
||||
/// Executable file name.
|
||||
fn executable_name() -> &'static str;
|
||||
///
|
||||
/// Extracts the file name from `std::env::current_exe()`.
|
||||
/// Resorts to the env var `CARGO_PKG_NAME` in case of Error.
|
||||
fn executable_name() -> String {
|
||||
std::env::current_exe().ok()
|
||||
.and_then(|e| e.file_name().map(|s| s.to_os_string()))
|
||||
.and_then(|w| w.into_string().ok())
|
||||
.unwrap_or_else(|| env!("CARGO_PKG_NAME").into())
|
||||
}
|
||||
|
||||
/// Executable file description.
|
||||
fn description() -> &'static str;
|
||||
fn description() -> String;
|
||||
|
||||
/// Executable file author.
|
||||
fn author() -> &'static str;
|
||||
fn author() -> String;
|
||||
|
||||
/// Support URL.
|
||||
fn support_url() -> &'static str;
|
||||
fn support_url() -> String;
|
||||
|
||||
/// Copyright starting year (x-current year)
|
||||
fn copyright_start_year() -> i32;
|
||||
@@ -116,13 +124,16 @@ pub trait SubstrateCli: Sized {
|
||||
{
|
||||
let app = <Self as StructOpt>::clap();
|
||||
|
||||
let mut full_version = Self::impl_version().to_string();
|
||||
let mut full_version = Self::impl_version();
|
||||
full_version.push_str("\n");
|
||||
|
||||
let name = Self::executable_name();
|
||||
let author = Self::author();
|
||||
let about = Self::description();
|
||||
let app = app
|
||||
.name(Self::executable_name())
|
||||
.author(Self::author())
|
||||
.about(Self::description())
|
||||
.name(name)
|
||||
.author(author.as_str())
|
||||
.about(about.as_str())
|
||||
.version(full_version.as_str())
|
||||
.settings(&[
|
||||
AppSettings::GlobalVersion,
|
||||
@@ -175,13 +186,16 @@ pub trait SubstrateCli: Sized {
|
||||
{
|
||||
let app = <Self as StructOpt>::clap();
|
||||
|
||||
let mut full_version = Self::impl_version().to_string();
|
||||
let mut full_version = Self::impl_version();
|
||||
full_version.push_str("\n");
|
||||
|
||||
let name = Self::executable_name();
|
||||
let author = Self::author();
|
||||
let about = Self::description();
|
||||
let app = app
|
||||
.name(Self::executable_name())
|
||||
.author(Self::author())
|
||||
.about(Self::description())
|
||||
.name(name)
|
||||
.author(author.as_str())
|
||||
.about(about.as_str())
|
||||
.version(full_version.as_str());
|
||||
|
||||
let matches = app.get_matches_from_safe(iter)?;
|
||||
|
||||
@@ -1203,8 +1203,8 @@ fn build_telemetry<TBl: BlockT>(
|
||||
let is_authority = config.role.is_authority();
|
||||
let network_id = network.local_peer_id().to_base58();
|
||||
let name = config.network.node_name.clone();
|
||||
let impl_name = config.impl_name.to_owned();
|
||||
let version = config.impl_version;
|
||||
let impl_name = config.impl_name.clone();
|
||||
let impl_version = config.impl_version.clone();
|
||||
let chain_name = config.chain_spec.name().to_owned();
|
||||
let telemetry = sc_telemetry::init_telemetry(sc_telemetry::TelemetryConfig {
|
||||
endpoints,
|
||||
@@ -1221,7 +1221,7 @@ fn build_telemetry<TBl: BlockT>(
|
||||
telemetry!(SUBSTRATE_INFO; "system.connected";
|
||||
"name" => name.clone(),
|
||||
"implementation" => impl_name.clone(),
|
||||
"version" => version,
|
||||
"version" => impl_version.clone(),
|
||||
"config" => "",
|
||||
"chain" => chain_name.clone(),
|
||||
"genesis_hash" => ?genesis_hash,
|
||||
@@ -1270,8 +1270,8 @@ fn gen_handler<TBl, TBackend, TExPool, TRpc, TCl>(
|
||||
|
||||
let system_info = sc_rpc::system::SystemInfo {
|
||||
chain_name: config.chain_spec.name().into(),
|
||||
impl_name: config.impl_name.into(),
|
||||
impl_version: config.impl_version.into(),
|
||||
impl_name: config.impl_name.clone(),
|
||||
impl_version: config.impl_version.clone(),
|
||||
properties: config.chain_spec.properties(),
|
||||
chain_type: config.chain_spec.chain_type(),
|
||||
};
|
||||
|
||||
@@ -37,9 +37,9 @@ use tempfile::TempDir;
|
||||
#[derive(Debug)]
|
||||
pub struct Configuration {
|
||||
/// Implementation name
|
||||
pub impl_name: &'static str,
|
||||
pub impl_name: String,
|
||||
/// Implementation version (see sc-cli to see an example of format)
|
||||
pub impl_version: &'static str,
|
||||
pub impl_version: String,
|
||||
/// Node role.
|
||||
pub role: Role,
|
||||
/// How to spawn background tasks. Mandatory, otherwise creating a `Service` will error.
|
||||
|
||||
@@ -229,8 +229,8 @@ fn node_config<G: RuntimeGenesis + 'static, E: ChainSpecExtension + Clone + 'sta
|
||||
};
|
||||
|
||||
Configuration {
|
||||
impl_name: "network-test-impl",
|
||||
impl_version: "0.1",
|
||||
impl_name: String::from("network-test-impl"),
|
||||
impl_version: String::from("0.1"),
|
||||
role,
|
||||
task_executor,
|
||||
transaction_pool: Default::default(),
|
||||
|
||||
Reference in New Issue
Block a user