Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
--version commit hash - style improvement (#496) (#547)
Browse files Browse the repository at this point in the history
* Update lib.rs

* Update lib.rs

* Update config.rs

* Update lib.rs

* Update lib.rs

* tab correction
  • Loading branch information
arkpar authored Aug 10, 2018
1 parent 7d79dd9 commit 7f0ed3a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
7 changes: 5 additions & 2 deletions substrate/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ extern crate exit_future;

#[macro_use]
extern crate lazy_static;
#[macro_use]
extern crate clap;
#[macro_use]
extern crate error_chain;
Expand Down Expand Up @@ -168,14 +167,18 @@ where
{
panic_hook::set();

let full_version = service::config::full_version_from_strs(
version.version,
version.commit
);
let yaml = format!(include_str!("./cli.yml"),
name = version.executable_name,
description = version.description,
author = version.author,
);
let yaml = &clap::YamlLoader::load_from_str(&yaml).expect("Invalid yml file")[0];
let matches = match clap::App::from_yaml(yaml)
.version(&(crate_version!().to_owned() + "\n")[..])
.version(&(full_version + "\n")[..])
.get_matches_from_safe(args) {
Ok(m) => m,
Err(e) => e.exit(),
Expand Down
26 changes: 16 additions & 10 deletions substrate/service/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,21 +101,27 @@ impl<C: Default, G: Serialize + DeserializeOwned + BuildStorage> Configuration<C
configuration
}

/// Returns platform info
pub fn platform() -> String {
let env = Target::env();
let env_dash = if env.is_empty() { "" } else { "-" };
format!("{}-{}{}{}", Target::arch(), Target::os(), env_dash, env)
}

/// Returns full version string.
/// Returns full version string of this configuration.
pub fn full_version(&self) -> String {
let commit_dash = if self.impl_commit.is_empty() { "" } else { "-" };
format!("{}{}{}-{}", self.impl_version, commit_dash, self.impl_commit, Self::platform())
full_version_from_strs(self.impl_version, self.impl_commit)
}

/// Implementation id and version.
pub fn client_id(&self) -> String {
format!("{}/v{}", self.impl_name, self.full_version())
}
}

/// Returns platform info
pub fn platform() -> String {
let env = Target::env();
let env_dash = if env.is_empty() { "" } else { "-" };
format!("{}-{}{}{}", Target::arch(), Target::os(), env_dash, env)
}

/// Returns full version string, using supplied version and commit.
pub fn full_version_from_strs(impl_version: &str, impl_commit: &str) -> String {
let commit_dash = if impl_commit.is_empty() { "" } else { "-" };
format!("{}{}{}-{}", impl_version, commit_dash, impl_commit, platform())
}

2 changes: 1 addition & 1 deletion substrate/service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ extern crate serde_derive;

mod components;
mod error;
mod config;
mod chain_spec;
pub mod config;
pub mod chain_ops;

use std::io;
Expand Down

0 comments on commit 7f0ed3a

Please sign in to comment.