Add option to format output as json
This commit is contained in:
17
src/main.rs
17
src/main.rs
@@ -38,6 +38,9 @@ const DHCP_RELAY_AGENT_AND_SERVER_PORT: u16 = 547;
|
||||
struct Cli {
|
||||
/// Network interface name used for DHCPv6
|
||||
interface: String,
|
||||
/// Format output as json
|
||||
#[arg(long)]
|
||||
json: bool,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
@@ -154,9 +157,17 @@ async fn main() -> Result<()>{
|
||||
};
|
||||
|
||||
let message_map = message_to_map(&response_msg);
|
||||
let message_map_yaml = serde_yaml::to_string(&message_map)
|
||||
.context("Unable to format message to yaml")?;
|
||||
println!("{}", message_map_yaml);
|
||||
|
||||
if cli.json {
|
||||
let message_map_json = serde_json::to_string(&message_map)
|
||||
.context("Unable to format message to json")?;
|
||||
println!("{}", message_map_json);
|
||||
}
|
||||
else {
|
||||
let message_map_yaml = serde_yaml::to_string(&message_map)
|
||||
.context("Unable to format message to yaml")?;
|
||||
println!("{}", message_map_yaml);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
Reference in New Issue
Block a user