Skip to content
Snippets Groups Projects
Commit 4abc16e7 authored by Hugo Trentesaux's avatar Hugo Trentesaux
Browse files

implement config formatter

parent bea7e02e
No related branches found
No related tags found
1 merge request!11refac call submission and event watch
This commit is part of merge request !11. Comments created here will be created in the context of that merge request.
......@@ -66,3 +66,9 @@ Secret and/or public keys can always be passed using `--secret` and `--address`.
Secret key format can be changed using `--secret-format` with the following values:
* `substrate`: a Substrate secret address (optionally followed by a derivation path), or BIP39 mnemonic
* `seed`: a 32-bytes seed in hexadecimal (Duniter v1 compatible)
## TODO
- [x] implement config formatter
- [ ] add link/unlink account commands
- [ ] migrate all xt to submit_call_and_look_event
\ No newline at end of file
......@@ -27,6 +27,25 @@ impl std::default::Default for Config {
}
}
impl std::fmt::Display for Config {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let secret = if self.secret.is_some() {
"(secret defined)"
} else {
"(no secret)"
};
let address = if let Some(address) = &self.address {
format!("{}", address)
} else {
"(no address)".to_string()
};
writeln!(f, "Ğcli config")?;
writeln!(f, "duniter endpoint {}", self.duniter_endpoint)?;
writeln!(f, "indexer endpoint {}", self.indexer_endpoint)?;
write!(f, "address {address} {secret}")
}
}
/// load config file and manage error if could not
pub fn load_conf() -> Config {
match confy::load(APP_NAME, None) {
......@@ -68,7 +87,7 @@ pub fn handle_command(data: Data, command: Subcommand) -> anyhow::Result<()> {
);
}
Subcommand::Show => {
println!("{:?}", data.cfg);
println!("{}", data.cfg);
}
Subcommand::Save => {
confy::store(APP_NAME, None, &data.cfg).expect("unable to write config");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment