Skip to content

Commit

Permalink
fix(snot-cli): fix errors not printing
Browse files Browse the repository at this point in the history
  • Loading branch information
gluax committed Mar 29, 2024
1 parent 83c4ef2 commit 2d23b5c
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions crates/snot-cli/src/commands/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,32 +39,36 @@ enum Commands {
impl Env {
pub fn run(self) -> Result<()> {
let client = reqwest::blocking::Client::new();
println!("testing caching");

use Commands::*;
match self.command {
let response = match self.command {
Prepare { spec } => {
let ep = format!("{}/api/v1/env/prepare", self.url);
let file: String = std::fs::read_to_string(spec)?;

let id: Value = client.post(&ep).body(file).send()?.json()?;
println!("{}", serde_json::to_string(&id)?);
Ok(())
client.post(ep).body(file).send()?
}

Start { id } => {
let ep = format!("{}/api/v1/env/{id}", self.url);

client.post(&ep).send()?;
Ok(())
client.post(ep).send()?
}

Stop { id } => {
let ep = format!("{}/api/v1/env/{id}", self.url);

client.delete(&ep).send()?;
Ok(())
client.delete(ep).send()?
}
}
};

let value = match response.content_length() {
Some(0) | None => None,
_ => response.json::<Value>().map(Some)?,
};

println!("{}", serde_json::to_string_pretty(&value)?);

Ok(())
}
}

0 comments on commit 2d23b5c

Please sign in to comment.