This repository has been archived by the owner on Sep 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(cli): expose version, author and app_name to be customized (#456)
- Loading branch information
1 parent
ffb1b45
commit 93c551e
Showing
4 changed files
with
84 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,15 +38,27 @@ impl<'a, Mapping> Cli<'a, Mapping> | |
where | ||
Mapping: 'static + ServiceMapping, | ||
{ | ||
pub fn run(service_mapping: Mapping, target_commands: Option<Vec<&str>>) { | ||
let cli = Self::new(service_mapping, target_commands); | ||
pub fn run( | ||
service_mapping: Mapping, | ||
app_name: &str, | ||
version: &str, | ||
author: &str, | ||
target_commands: Option<Vec<&str>>, | ||
) { | ||
let cli = Self::new(service_mapping, app_name, version, author, target_commands); | ||
if let Err(e) = cli.start() { | ||
log::error!("{:?}", e) | ||
} | ||
} | ||
|
||
pub fn new(service_mapping: Mapping, target_commands: Option<Vec<&str>>) -> Self { | ||
let matches = Self::generate_matches(target_commands); | ||
pub fn new( | ||
service_mapping: Mapping, | ||
app_name: &str, | ||
version: &str, | ||
author: &str, | ||
target_commands: Option<Vec<&str>>, | ||
) -> Self { | ||
let matches = Self::generate_matches(app_name, version, author, target_commands); | ||
|
||
let config_path = matches.value_of("config").expect("missing config path"); | ||
|
||
|
@@ -136,10 +148,15 @@ where | |
} | ||
} | ||
|
||
pub fn generate_matches(cmds: Option<Vec<&str>>) -> ArgMatches<'a> { | ||
let app = clap::App::new("muta-chain") | ||
.version("v0.2.0-rc.2.1") | ||
.author("Muta Dev <[email protected]>") | ||
pub fn generate_matches( | ||
app_name: &str, | ||
version: &str, | ||
author: &str, | ||
cmds: Option<Vec<&str>>, | ||
) -> ArgMatches<'a> { | ||
let app = clap::App::new(app_name) | ||
.version(version) | ||
.author(author) | ||
.arg( | ||
clap::Arg::with_name("config") | ||
.short("c") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,7 +52,13 @@ impl ServiceMapping for DefaultServiceMapping { | |
} | ||
|
||
pub fn main() { | ||
muta::run(DefaultServiceMapping, None) | ||
muta::run( | ||
DefaultServiceMapping, | ||
"muta-chain", | ||
"v0.2.0-rc.2.1", | ||
"Muta Dev <[email protected]>", | ||
None, | ||
) | ||
} | ||
|
||
#[derive(Debug, Display, From)] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters