From 4901507891a0dde1dd40e5173a02b4ef81bd82f5 Mon Sep 17 00:00:00 2001 From: Tino Rusch Date: Mon, 11 Nov 2024 13:00:10 +0100 Subject: [PATCH] respect the --format flag everywhere --- Cargo.lock | 4 +-- src/commands/pins.rs | 13 +++++++-- src/commands/sudo.rs | 47 ++++++++++++++++++++--------- src/commands/tasks.rs | 11 +++++-- src/commands/workers.rs | 17 ++++++++--- src/main.rs | 65 +++++++++++++++++++++++++++++++++++------ 6 files changed, 124 insertions(+), 33 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 97d1c41..11e9494 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -901,7 +901,7 @@ dependencies = [ [[package]] name = "gevulot-rs" version = "0.1.0" -source = "git+https://github.com/gevulotnetwork/gevulot-rs.git?rev=6695dcb0e7214a3ec07cdc2d83bbc4ff26ae2d38#6695dcb0e7214a3ec07cdc2d83bbc4ff26ae2d38" +source = "git+https://github.com/gevulotnetwork/gevulot-rs.git?rev=28b6c9f39ebe8144cbd8eac746d7ada5b8646268#28b6c9f39ebe8144cbd8eac746d7ada5b8646268" dependencies = [ "backon", "bip32", @@ -958,7 +958,7 @@ dependencies = [ [[package]] name = "gvltctl" -version = "0.1.1" +version = "0.1.2" dependencies = [ "anyhow", "bip32", diff --git a/src/commands/pins.rs b/src/commands/pins.rs index 4f17fff..bc82975 100644 --- a/src/commands/pins.rs +++ b/src/commands/pins.rs @@ -84,7 +84,11 @@ pub async fn create_pin(_sub_m: &clap::ArgMatches) -> Result<(), Box Result<(), Box Result<(), Box> { - println!("Deleting a pin"); let pin_cid = _sub_m .get_one::("cid") .ok_or("Pin CID is required")?; @@ -123,6 +126,10 @@ pub async fn delete_pin(_sub_m: &clap::ArgMatches) -> Result<(), Box clap::Command { Command::new("sudo") @@ -83,9 +80,15 @@ pub async fn sudo_delete_pin(_sub_m: &clap::ArgMatches) -> Result<(), Box Result<(), Box Result<(), Box Result<(), Box Result<(), Box Result<(), Box Result<(), Box Result<(), Box Result<(), Box if an error occurs. pub async fn delete_worker(_sub_m: &clap::ArgMatches) -> Result<(), Box> { - println!("Deleting a worker"); let worker_id = _sub_m .get_one::("id") .ok_or("Worker ID is required")?; @@ -117,6 +123,9 @@ pub async fn delete_worker(_sub_m: &clap::ArgMatches) -> Result<(), Box Result<(), Box Result<(), Box Result<(), Box("file") { let mut file = File::create(file)?; - file.write_all(mnemonic.phrase().as_bytes())?; - } else { - println!("{}", mnemonic.phrase()); + file.write_all(phrase.as_bytes())?; + } + + match _sub_m.get_one::("format").map(String::as_str) { + Some("json") => { + let json = serde_json::to_string(&output)?; + println!("{}", json); + } + Some("prettyjson") => { + let prettyjson = serde_json::to_string_pretty(&output)?; + println!("{}", prettyjson); + } + Some("toml") => { + let toml = toml::to_string(&output)?; + println!("{}", toml); + } + Some("yaml") => { + let yaml = serde_yaml::to_string(&output)?; + println!("{}", yaml); + } + _ => { + println!("{}", account_id); + println!("{}", phrase); + } } Ok(()) @@ -686,8 +727,10 @@ async fn compute_key(_sub_m: &clap::ArgMatches) -> Result<(), Box Result<(), Box Result<(), Box> { - println!("Listing all workflows"); + let output = serde_json::json!({ + "message": "Listing all workflows", + "status": "not_implemented" + }); + print_object(_sub_m, &output)?; todo!(); }