Skip to content

Commit 10546ea

Browse files
committed
oasis cli: move --json flag to relevant subcommand
1 parent bceb7cd commit 10546ea

1 file changed

Lines changed: 7 additions & 12 deletions

File tree

code/client/src/main.rs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ struct Args {
2929

3030
#[command(subcommand)]
3131
command: Commands,
32-
33-
#[arg(long, help = "If true, output is printed in json format")]
34-
json: bool,
3532
}
3633

3734
#[derive(Subcommand, Debug)]
@@ -42,7 +39,10 @@ enum Commands {
4239
overrides: Vec<String>,
4340
},
4441
/// Get the temperature and humidity of the terrarium, as well as the current state of the lights, fans, and mister.
45-
State,
42+
State {
43+
#[arg(long, help = "If true, output is printed in json format")]
44+
json: bool,
45+
},
4646
/// Get or set the terrarium configuration. This includes wifi details and schedule.
4747
Config {
4848
#[arg(long)]
@@ -100,7 +100,7 @@ async fn main() -> anyhow::Result<()> {
100100
return Err(anyhow!("Control failed: {}", resp.text().await?));
101101
}
102102
}
103-
Commands::State => {
103+
Commands::State { json } => {
104104
log::info!("Connecting to terrarium at '{addr}'...");
105105
let client = reqwest::Client::new();
106106

@@ -114,7 +114,7 @@ async fn main() -> anyhow::Result<()> {
114114
}
115115

116116
let text = resp.text().await.unwrap();
117-
if args.json {
117+
if *json {
118118
println!("{text}");
119119
} else {
120120
let state: TerrariumState = serde_json::from_str(&text).unwrap();
@@ -161,12 +161,7 @@ async fn main() -> anyhow::Result<()> {
161161
}
162162

163163
let text = resp.text().await.unwrap();
164-
if args.json {
165-
println!("{text}");
166-
} else {
167-
// TODO: format it not as json
168-
println!("{text}");
169-
}
164+
println!("{text}");
170165
}
171166
}
172167
Commands::Scan { timeout } => {

0 commit comments

Comments
 (0)