mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-04-28 03:00:18 -04:00
add config arg to wallet cli & add subcommands to config arg
This commit is contained in:
@@ -227,12 +227,19 @@ async fn start(
|
||||
fn main() -> Result<()> {
|
||||
use simplelog::*;
|
||||
|
||||
let mut config = cli_config::Config::load(PathBuf::from("darkfid_config_file"))?;
|
||||
let options = Arc::new(WalletCli::load(&mut config)?);
|
||||
|
||||
if options.change_config {
|
||||
config.save(PathBuf::from("darkfid_config_file"))?;
|
||||
std::process::exit(-1);
|
||||
}
|
||||
|
||||
let config = Arc::new(config);
|
||||
|
||||
let ex = Arc::new(Executor::new());
|
||||
let (signal, shutdown) = async_channel::unbounded::<()>();
|
||||
|
||||
let options = Arc::new(WalletCli::load()?);
|
||||
let config = Arc::new(cli_config::Config::load(PathBuf::from("darkfid_config_file"))?);
|
||||
|
||||
let logger_config = ConfigBuilder::new().set_time_format_str("%T%.6f").build();
|
||||
|
||||
let debug_level = if options.verbose {
|
||||
|
||||
@@ -2,11 +2,7 @@ use crate::serial::{deserialize, serialize, Decodable, Encodable};
|
||||
use crate::util::join_config_path;
|
||||
use crate::Result;
|
||||
|
||||
use std::{
|
||||
fs::OpenOptions,
|
||||
io::prelude::*,
|
||||
path::PathBuf,
|
||||
};
|
||||
use std::{fs::OpenOptions, io::prelude::*, path::PathBuf};
|
||||
|
||||
pub struct Config {
|
||||
pub connect_url: String,
|
||||
@@ -21,7 +17,16 @@ impl Default for Config {
|
||||
let connect_url = String::from("127.0.0.1:3333");
|
||||
let subscriber_url = String::from("127.0.0.1:4444");
|
||||
let rpc_url = String::from("127.0.0.1:8000");
|
||||
|
||||
let database_path = String::from("database_client.db");
|
||||
let database_path = join_config_path(&PathBuf::from(database_path))
|
||||
.expect("error during join database_path to config path");
|
||||
let database_path = String::from(
|
||||
database_path
|
||||
.to_str()
|
||||
.expect("error convert Path to String"),
|
||||
);
|
||||
|
||||
let log_path = String::from("/tmp/darkfid_service_daemon.log");
|
||||
Self {
|
||||
connect_url,
|
||||
@@ -62,7 +67,10 @@ pub fn load_config_file(config_file: PathBuf) -> Result<Config> {
|
||||
}
|
||||
|
||||
pub fn save_config_file(config: &Config, config_file: PathBuf) -> Result<()> {
|
||||
let mut file = OpenOptions::new().write(true).create(true).open(&config_file)?;
|
||||
let mut file = OpenOptions::new()
|
||||
.write(true)
|
||||
.create(true)
|
||||
.open(&config_file)?;
|
||||
let serialized = serialize(config);
|
||||
file.write_all(&serialized)?;
|
||||
Ok(())
|
||||
|
||||
@@ -1,28 +1,109 @@
|
||||
use crate::cli::cli_config;
|
||||
use crate::Result;
|
||||
|
||||
use clap::{App, Arg};
|
||||
use clap::{App, AppSettings, Arg};
|
||||
|
||||
pub struct WalletCli {
|
||||
pub change_config: bool,
|
||||
pub verbose: bool,
|
||||
}
|
||||
|
||||
impl WalletCli {
|
||||
pub fn load() -> Result<Self> {
|
||||
pub fn load(config: &mut cli_config::Config) -> Result<Self> {
|
||||
let app = App::new("Wallet CLI")
|
||||
.version("0.1.0")
|
||||
.author("Amir Taaki <amir@dyne.org>")
|
||||
.about("Run Service Client")
|
||||
.about("Run Wallet CLi")
|
||||
.arg(
|
||||
Arg::new("verbose")
|
||||
.short('v')
|
||||
.help_heading(Some("Increase verbosity"))
|
||||
.long("verbose")
|
||||
.takes_value(false)
|
||||
).get_matches();
|
||||
.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("connect_url")
|
||||
.about("Set Connect Url")
|
||||
.long("connect-url")
|
||||
.takes_value(true),
|
||||
Arg::new("subscriber_url")
|
||||
.about("Set Subscriber Url")
|
||||
.long("subscriber-url")
|
||||
.takes_value(true),
|
||||
Arg::new("rpc_url")
|
||||
.about("Set RPC Url")
|
||||
.long("rpc-url")
|
||||
.takes_value(true),
|
||||
Arg::new("database_path")
|
||||
.about("Set Database Path")
|
||||
.long("database-path")
|
||||
.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!("Connect Url: {}", config.connect_url);
|
||||
println!("Subscriber Url: {}", config.subscriber_url);
|
||||
println!("RPC Url: {}", config.rpc_url);
|
||||
println!("Database path: {}", config.database_path);
|
||||
println!("Log Path: {}", config.log_path);
|
||||
}
|
||||
("set", c) => {
|
||||
change_config = true;
|
||||
if let Some(v) = c.value_of("connect_url") {
|
||||
config.connect_url = v.to_string();
|
||||
println!("Change Connect Url To {}", config.connect_url);
|
||||
}
|
||||
if let Some(v) = c.value_of("subscriber_url") {
|
||||
config.subscriber_url = v.to_string();
|
||||
println!("Change Subscriber Url To {}", config.connect_url);
|
||||
}
|
||||
if let Some(v) = c.value_of("rpc_url") {
|
||||
config.rpc_url = v.to_string();
|
||||
println!("Change RPC Url To {}", config.connect_url);
|
||||
}
|
||||
if let Some(v) = c.value_of("database_path") {
|
||||
config.database_path = v.to_string();
|
||||
println!("Change Database Path To {}", config.connect_url);
|
||||
}
|
||||
if let Some(v) = c.value_of("log_path") {
|
||||
config.log_path = v.to_string();
|
||||
println!("Change Log Path To {}", config.connect_url);
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
},
|
||||
None => {}
|
||||
},
|
||||
None => {}
|
||||
}
|
||||
|
||||
Ok(Self {
|
||||
change_config,
|
||||
verbose,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user