mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-04-28 03:00:18 -04:00
create Darkfi client cli
This commit is contained in:
83
src/cli/client_cli/darkfi_cli.rs
Normal file
83
src/cli/client_cli/darkfi_cli.rs
Normal file
@@ -0,0 +1,83 @@
|
||||
use super::cli_config::DarkfiCliConfig;
|
||||
use crate::Result;
|
||||
|
||||
use clap::{App, AppSettings, Arg};
|
||||
|
||||
pub struct DarkfiCli {
|
||||
pub change_config: bool,
|
||||
pub verbose: bool,
|
||||
}
|
||||
|
||||
impl DarkfiCli {
|
||||
pub fn load(config: &mut DarkfiCliConfig) -> Result<Self> {
|
||||
let app = App::new("Darkfi CLI")
|
||||
.version("0.1.0")
|
||||
.author("Amir Taaki <amir@dyne.org>")
|
||||
.about("Run Darkfi Client")
|
||||
.arg(
|
||||
Arg::new("verbose")
|
||||
.short('v')
|
||||
.help_heading(Some("Increase verbosity"))
|
||||
.long("verbose")
|
||||
.takes_value(false),
|
||||
)
|
||||
.subcommand(
|
||||
App::new("config")
|
||||
.about("Configuration settings")
|
||||
.aliases(&["get", "set"])
|
||||
.setting(AppSettings::SubcommandRequiredElseHelp)
|
||||
.subcommand(App::new("get").about("Get configuration settings"))
|
||||
.subcommand(
|
||||
App::new("set")
|
||||
.about("Set configuration settings")
|
||||
.args(&[
|
||||
Arg::new("rpc_url")
|
||||
.about("Set RPC Url")
|
||||
.long("rpc-url")
|
||||
.takes_value(true),
|
||||
Arg::new("log_path")
|
||||
.about("Set Log Path")
|
||||
.long("log-path")
|
||||
.takes_value(true),
|
||||
])
|
||||
.setting(AppSettings::ArgRequiredElseHelp),
|
||||
),
|
||||
)
|
||||
.get_matches();
|
||||
|
||||
let mut change_config = false;
|
||||
|
||||
let verbose = app.is_present("verbose");
|
||||
|
||||
match app.subcommand_matches("config") {
|
||||
Some(config_sub) => match config_sub.subcommand() {
|
||||
Some(c) => match c {
|
||||
("get", _) => {
|
||||
change_config = true;
|
||||
println!("RPC Url: {}", config.rpc_url);
|
||||
println!("Log Path: {}", config.log_path);
|
||||
}
|
||||
("set", c) => {
|
||||
change_config = true;
|
||||
if let Some(v) = c.value_of("rpc_url") {
|
||||
config.rpc_url = v.to_string();
|
||||
println!("Change RPC Url To {}", config.rpc_url);
|
||||
}
|
||||
if let Some(v) = c.value_of("log_path") {
|
||||
config.log_path = v.to_string();
|
||||
println!("Change Log Path To {}", config.log_path);
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
},
|
||||
None => {}
|
||||
},
|
||||
None => {}
|
||||
}
|
||||
|
||||
Ok(Self {
|
||||
change_config,
|
||||
verbose,
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user