From 39bef981a13701aaca944e50c5354487d528d977 Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Mon, 10 Jun 2019 14:21:09 +0200 Subject: zotcli: Make group formatting work and print flags. Formatting requires the format arguments to be proper strings or integers. Formatting a serde_json::Value directly did not work. --- examples/zot/group.rs | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/examples/zot/group.rs b/examples/zot/group.rs index 71f60d6..6bb3839 100644 --- a/examples/zot/group.rs +++ b/examples/zot/group.rs @@ -24,11 +24,26 @@ pub fn list(data: &str) { println!("----+------------------+-----+-------+-------------------------"); for group in groups { - println!("{:4} | {:16} | {:3} | | {}", - group["id"], - group["gname"], - group["uid"], - group["hash"]) + let mut flags = String::new(); + + if let Some(visible) = group["visible"].as_u64() { + if visible != 0 { + flags += "v"; + } + } + + if let Some(deleted) = group["deleted"].as_u64() { + if deleted != 0 { + flags += "d"; + } + } + + print!("{:>3} | {:16} | {:>3} | {:5} | {}\n", + group["id"].as_u64().unwrap(), + group["gname"].as_str().unwrap(), + group["uid"].as_u64().unwrap(), + flags, + group["hash"].as_str().unwrap()); } } else { -- cgit v1.2.3