CLI: handling of no-content responses is lousy (#805)

This commit is contained in:
Adam Leventhal 2024-05-15 11:04:45 -07:00 committed by GitHub
parent 3dd09970a8
commit c59c6d64ed
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 387 additions and 373 deletions

View File

@ -1,4 +1,4 @@
// Copyright 2023 Oxide Computer Company // Copyright 2024 Oxide Computer Company
use std::collections::BTreeMap; use std::collections::BTreeMap;
@ -149,10 +149,11 @@ impl Generator {
} }
pub trait CliConfig { pub trait CliConfig {
fn item_success<T>(&self, value: &ResponseValue<T>) fn success_item<T>(&self, value: &ResponseValue<T>)
where where
T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug; T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
fn item_error<T>(&self, value: &Error<T>) fn success_no_item(&self, value: &ResponseValue<()>);
fn error<T>(&self, value: &Error<T>)
where where
T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug; T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
@ -241,11 +242,18 @@ impl Generator {
// Normal, one-shot API calls. // Normal, one-shot API calls.
None => { None => {
let success_output = match success_kind { let success_output = match success_kind {
crate::method::OperationResponseKind::Type(_) crate::method::OperationResponseKind::Type(_) => {
| crate::method::OperationResponseKind::None => {
quote! { quote! {
{ {
self.config.item_success(&r); self.config.success_item(&r);
Ok(())
}
}
}
crate::method::OperationResponseKind::None => {
quote! {
{
self.config.success_no_item(&r);
Ok(()) Ok(())
} }
} }
@ -265,7 +273,7 @@ impl Generator {
| crate::method::OperationResponseKind::None => { | crate::method::OperationResponseKind::None => {
quote! { quote! {
{ {
self.config.item_error(&r); self.config.error(&r);
Err(anyhow::Error::new(r)) Err(anyhow::Error::new(r))
} }
} }

View File

@ -348,11 +348,11 @@ impl<T: CliConfig> Cli<T> {
let result = request.send().await; let result = request.send().await;
match result { match result {
Ok(r) => { Ok(r) => {
self.config.item_success(&r); self.config.success_item(&r);
Ok(()) Ok(())
} }
Err(r) => { Err(r) => {
self.config.item_error(&r); self.config.error(&r);
Err(anyhow::Error::new(r)) Err(anyhow::Error::new(r))
} }
} }
@ -364,11 +364,11 @@ impl<T: CliConfig> Cli<T> {
let result = request.send().await; let result = request.send().await;
match result { match result {
Ok(r) => { Ok(r) => {
self.config.item_success(&r); self.config.success_no_item(&r);
Ok(()) Ok(())
} }
Err(r) => { Err(r) => {
self.config.item_error(&r); self.config.error(&r);
Err(anyhow::Error::new(r)) Err(anyhow::Error::new(r))
} }
} }
@ -384,11 +384,11 @@ impl<T: CliConfig> Cli<T> {
let result = request.send().await; let result = request.send().await;
match result { match result {
Ok(r) => { Ok(r) => {
self.config.item_success(&r); self.config.success_item(&r);
Ok(()) Ok(())
} }
Err(r) => { Err(r) => {
self.config.item_error(&r); self.config.error(&r);
Err(anyhow::Error::new(r)) Err(anyhow::Error::new(r))
} }
} }
@ -400,11 +400,11 @@ impl<T: CliConfig> Cli<T> {
let result = request.send().await; let result = request.send().await;
match result { match result {
Ok(r) => { Ok(r) => {
self.config.item_success(&r); self.config.success_item(&r);
Ok(()) Ok(())
} }
Err(r) => { Err(r) => {
self.config.item_error(&r); self.config.error(&r);
Err(anyhow::Error::new(r)) Err(anyhow::Error::new(r))
} }
} }
@ -430,11 +430,11 @@ impl<T: CliConfig> Cli<T> {
let result = request.send().await; let result = request.send().await;
match result { match result {
Ok(r) => { Ok(r) => {
self.config.item_success(&r); self.config.success_item(&r);
Ok(()) Ok(())
} }
Err(r) => { Err(r) => {
self.config.item_error(&r); self.config.error(&r);
Err(anyhow::Error::new(r)) Err(anyhow::Error::new(r))
} }
} }
@ -454,11 +454,11 @@ impl<T: CliConfig> Cli<T> {
let result = request.send().await; let result = request.send().await;
match result { match result {
Ok(r) => { Ok(r) => {
self.config.item_success(&r); self.config.success_item(&r);
Ok(()) Ok(())
} }
Err(r) => { Err(r) => {
self.config.item_error(&r); self.config.error(&r);
Err(anyhow::Error::new(r)) Err(anyhow::Error::new(r))
} }
} }
@ -475,11 +475,11 @@ impl<T: CliConfig> Cli<T> {
let result = request.send().await; let result = request.send().await;
match result { match result {
Ok(r) => { Ok(r) => {
self.config.item_success(&r); self.config.success_item(&r);
Ok(()) Ok(())
} }
Err(r) => { Err(r) => {
self.config.item_error(&r); self.config.error(&r);
Err(anyhow::Error::new(r)) Err(anyhow::Error::new(r))
} }
} }
@ -506,7 +506,7 @@ impl<T: CliConfig> Cli<T> {
todo!() todo!()
} }
Err(r) => { Err(r) => {
self.config.item_error(&r); self.config.error(&r);
Err(anyhow::Error::new(r)) Err(anyhow::Error::new(r))
} }
} }
@ -528,11 +528,11 @@ impl<T: CliConfig> Cli<T> {
let result = request.send().await; let result = request.send().await;
match result { match result {
Ok(r) => { Ok(r) => {
self.config.item_success(&r); self.config.success_item(&r);
Ok(()) Ok(())
} }
Err(r) => { Err(r) => {
self.config.item_error(&r); self.config.error(&r);
Err(anyhow::Error::new(r)) Err(anyhow::Error::new(r))
} }
} }
@ -544,11 +544,11 @@ impl<T: CliConfig> Cli<T> {
let result = request.send().await; let result = request.send().await;
match result { match result {
Ok(r) => { Ok(r) => {
self.config.item_success(&r); self.config.success_item(&r);
Ok(()) Ok(())
} }
Err(r) => { Err(r) => {
self.config.item_error(&r); self.config.error(&r);
Err(anyhow::Error::new(r)) Err(anyhow::Error::new(r))
} }
} }
@ -560,11 +560,11 @@ impl<T: CliConfig> Cli<T> {
let result = request.send().await; let result = request.send().await;
match result { match result {
Ok(r) => { Ok(r) => {
self.config.item_success(&r); self.config.success_no_item(&r);
Ok(()) Ok(())
} }
Err(r) => { Err(r) => {
self.config.item_error(&r); self.config.error(&r);
Err(anyhow::Error::new(r)) Err(anyhow::Error::new(r))
} }
} }
@ -591,11 +591,11 @@ impl<T: CliConfig> Cli<T> {
let result = request.send().await; let result = request.send().await;
match result { match result {
Ok(r) => { Ok(r) => {
self.config.item_success(&r); self.config.success_item(&r);
Ok(()) Ok(())
} }
Err(r) => { Err(r) => {
self.config.item_error(&r); self.config.error(&r);
Err(anyhow::Error::new(r)) Err(anyhow::Error::new(r))
} }
} }
@ -607,11 +607,11 @@ impl<T: CliConfig> Cli<T> {
let result = request.send().await; let result = request.send().await;
match result { match result {
Ok(r) => { Ok(r) => {
self.config.item_success(&r); self.config.success_item(&r);
Ok(()) Ok(())
} }
Err(r) => { Err(r) => {
self.config.item_error(&r); self.config.error(&r);
Err(anyhow::Error::new(r)) Err(anyhow::Error::new(r))
} }
} }
@ -649,11 +649,11 @@ impl<T: CliConfig> Cli<T> {
let result = request.send().await; let result = request.send().await;
match result { match result {
Ok(r) => { Ok(r) => {
self.config.item_success(&r); self.config.success_no_item(&r);
Ok(()) Ok(())
} }
Err(r) => { Err(r) => {
self.config.item_error(&r); self.config.error(&r);
Err(anyhow::Error::new(r)) Err(anyhow::Error::new(r))
} }
} }
@ -673,11 +673,11 @@ impl<T: CliConfig> Cli<T> {
let result = request.send().await; let result = request.send().await;
match result { match result {
Ok(r) => { Ok(r) => {
self.config.item_success(&r); self.config.success_item(&r);
Ok(()) Ok(())
} }
Err(r) => { Err(r) => {
self.config.item_error(&r); self.config.error(&r);
Err(anyhow::Error::new(r)) Err(anyhow::Error::new(r))
} }
} }
@ -707,11 +707,11 @@ impl<T: CliConfig> Cli<T> {
let result = request.send().await; let result = request.send().await;
match result { match result {
Ok(r) => { Ok(r) => {
self.config.item_success(&r); self.config.success_no_item(&r);
Ok(()) Ok(())
} }
Err(r) => { Err(r) => {
self.config.item_error(&r); self.config.error(&r);
Err(anyhow::Error::new(r)) Err(anyhow::Error::new(r))
} }
} }
@ -745,11 +745,11 @@ impl<T: CliConfig> Cli<T> {
let result = request.send().await; let result = request.send().await;
match result { match result {
Ok(r) => { Ok(r) => {
self.config.item_success(&r); self.config.success_no_item(&r);
Ok(()) Ok(())
} }
Err(r) => { Err(r) => {
self.config.item_error(&r); self.config.error(&r);
Err(anyhow::Error::new(r)) Err(anyhow::Error::new(r))
} }
} }
@ -761,11 +761,11 @@ impl<T: CliConfig> Cli<T> {
let result = request.send().await; let result = request.send().await;
match result { match result {
Ok(r) => { Ok(r) => {
self.config.item_success(&r); self.config.success_item(&r);
Ok(()) Ok(())
} }
Err(r) => { Err(r) => {
self.config.item_error(&r); self.config.error(&r);
Err(anyhow::Error::new(r)) Err(anyhow::Error::new(r))
} }
} }
@ -777,11 +777,11 @@ impl<T: CliConfig> Cli<T> {
let result = request.send().await; let result = request.send().await;
match result { match result {
Ok(r) => { Ok(r) => {
self.config.item_success(&r); self.config.success_no_item(&r);
Ok(()) Ok(())
} }
Err(r) => { Err(r) => {
self.config.item_error(&r); self.config.error(&r);
Err(anyhow::Error::new(r)) Err(anyhow::Error::new(r))
} }
} }
@ -789,10 +789,11 @@ impl<T: CliConfig> Cli<T> {
} }
pub trait CliConfig { pub trait CliConfig {
fn item_success<T>(&self, value: &ResponseValue<T>) fn success_item<T>(&self, value: &ResponseValue<T>)
where where
T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug; T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
fn item_error<T>(&self, value: &Error<T>) fn success_no_item(&self, value: &ResponseValue<()>);
fn error<T>(&self, value: &Error<T>)
where where
T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug; T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
fn list_start<T>(&self) fn list_start<T>(&self)

View File

@ -217,11 +217,11 @@ impl<T: CliConfig> Cli<T> {
let result = request.send().await; let result = request.send().await;
match result { match result {
Ok(r) => { Ok(r) => {
self.config.item_success(&r); self.config.success_no_item(&r);
Ok(()) Ok(())
} }
Err(r) => { Err(r) => {
self.config.item_error(&r); self.config.error(&r);
Err(anyhow::Error::new(r)) Err(anyhow::Error::new(r))
} }
} }
@ -237,11 +237,11 @@ impl<T: CliConfig> Cli<T> {
let result = request.send().await; let result = request.send().await;
match result { match result {
Ok(r) => { Ok(r) => {
self.config.item_success(&r); self.config.success_item(&r);
Ok(()) Ok(())
} }
Err(r) => { Err(r) => {
self.config.item_error(&r); self.config.error(&r);
Err(anyhow::Error::new(r)) Err(anyhow::Error::new(r))
} }
} }
@ -257,11 +257,11 @@ impl<T: CliConfig> Cli<T> {
let result = request.send().await; let result = request.send().await;
match result { match result {
Ok(r) => { Ok(r) => {
self.config.item_success(&r); self.config.success_item(&r);
Ok(()) Ok(())
} }
Err(r) => { Err(r) => {
self.config.item_error(&r); self.config.error(&r);
Err(anyhow::Error::new(r)) Err(anyhow::Error::new(r))
} }
} }
@ -295,11 +295,11 @@ impl<T: CliConfig> Cli<T> {
let result = request.send().await; let result = request.send().await;
match result { match result {
Ok(r) => { Ok(r) => {
self.config.item_success(&r); self.config.success_item(&r);
Ok(()) Ok(())
} }
Err(r) => { Err(r) => {
self.config.item_error(&r); self.config.error(&r);
Err(anyhow::Error::new(r)) Err(anyhow::Error::new(r))
} }
} }
@ -321,11 +321,11 @@ impl<T: CliConfig> Cli<T> {
let result = request.send().await; let result = request.send().await;
match result { match result {
Ok(r) => { Ok(r) => {
self.config.item_success(&r); self.config.success_item(&r);
Ok(()) Ok(())
} }
Err(r) => { Err(r) => {
self.config.item_error(&r); self.config.error(&r);
Err(anyhow::Error::new(r)) Err(anyhow::Error::new(r))
} }
} }
@ -356,11 +356,11 @@ impl<T: CliConfig> Cli<T> {
let result = request.send().await; let result = request.send().await;
match result { match result {
Ok(r) => { Ok(r) => {
self.config.item_success(&r); self.config.success_item(&r);
Ok(()) Ok(())
} }
Err(r) => { Err(r) => {
self.config.item_error(&r); self.config.error(&r);
Err(anyhow::Error::new(r)) Err(anyhow::Error::new(r))
} }
} }
@ -368,10 +368,11 @@ impl<T: CliConfig> Cli<T> {
} }
pub trait CliConfig { pub trait CliConfig {
fn item_success<T>(&self, value: &ResponseValue<T>) fn success_item<T>(&self, value: &ResponseValue<T>)
where where
T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug; T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
fn item_error<T>(&self, value: &Error<T>) fn success_no_item(&self, value: &ResponseValue<()>);
fn error<T>(&self, value: &Error<T>)
where where
T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug; T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
fn list_start<T>(&self) fn list_start<T>(&self)

File diff suppressed because it is too large Load Diff

View File

@ -98,11 +98,11 @@ impl<T: CliConfig> Cli<T> {
let result = request.send().await; let result = request.send().await;
match result { match result {
Ok(r) => { Ok(r) => {
self.config.item_success(&r); self.config.success_no_item(&r);
Ok(()) Ok(())
} }
Err(r) => { Err(r) => {
self.config.item_error(&r); self.config.error(&r);
Err(anyhow::Error::new(r)) Err(anyhow::Error::new(r))
} }
} }
@ -110,10 +110,11 @@ impl<T: CliConfig> Cli<T> {
} }
pub trait CliConfig { pub trait CliConfig {
fn item_success<T>(&self, value: &ResponseValue<T>) fn success_item<T>(&self, value: &ResponseValue<T>)
where where
T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug; T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
fn item_error<T>(&self, value: &Error<T>) fn success_no_item(&self, value: &ResponseValue<()>);
fn error<T>(&self, value: &Error<T>)
where where
T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug; T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
fn list_start<T>(&self) fn list_start<T>(&self)

View File

@ -54,11 +54,11 @@ impl<T: CliConfig> Cli<T> {
let result = request.send().await; let result = request.send().await;
match result { match result {
Ok(r) => { Ok(r) => {
self.config.item_success(&r); self.config.success_no_item(&r);
Ok(()) Ok(())
} }
Err(r) => { Err(r) => {
self.config.item_error(&r); self.config.error(&r);
Err(anyhow::Error::new(r)) Err(anyhow::Error::new(r))
} }
} }
@ -66,10 +66,11 @@ impl<T: CliConfig> Cli<T> {
} }
pub trait CliConfig { pub trait CliConfig {
fn item_success<T>(&self, value: &ResponseValue<T>) fn success_item<T>(&self, value: &ResponseValue<T>)
where where
T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug; T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
fn item_error<T>(&self, value: &Error<T>) fn success_no_item(&self, value: &ResponseValue<()>);
fn error<T>(&self, value: &Error<T>)
where where
T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug; T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
fn list_start<T>(&self) fn list_start<T>(&self)

View File

@ -161,11 +161,11 @@ impl<T: CliConfig> Cli<T> {
let result = request.send().await; let result = request.send().await;
match result { match result {
Ok(r) => { Ok(r) => {
self.config.item_success(&r); self.config.success_item(&r);
Ok(()) Ok(())
} }
Err(r) => { Err(r) => {
self.config.item_error(&r); self.config.error(&r);
Err(anyhow::Error::new(r)) Err(anyhow::Error::new(r))
} }
} }
@ -188,11 +188,11 @@ impl<T: CliConfig> Cli<T> {
let result = request.send().await; let result = request.send().await;
match result { match result {
Ok(r) => { Ok(r) => {
self.config.item_success(&r); self.config.success_item(&r);
Ok(()) Ok(())
} }
Err(r) => { Err(r) => {
self.config.item_error(&r); self.config.error(&r);
Err(anyhow::Error::new(r)) Err(anyhow::Error::new(r))
} }
} }
@ -216,11 +216,11 @@ impl<T: CliConfig> Cli<T> {
let result = request.send().await; let result = request.send().await;
match result { match result {
Ok(r) => { Ok(r) => {
self.config.item_success(&r); self.config.success_item(&r);
Ok(()) Ok(())
} }
Err(r) => { Err(r) => {
self.config.item_error(&r); self.config.error(&r);
Err(anyhow::Error::new(r)) Err(anyhow::Error::new(r))
} }
} }
@ -247,11 +247,11 @@ impl<T: CliConfig> Cli<T> {
let result = request.send().await; let result = request.send().await;
match result { match result {
Ok(r) => { Ok(r) => {
self.config.item_success(&r); self.config.success_item(&r);
Ok(()) Ok(())
} }
Err(r) => { Err(r) => {
self.config.item_error(&r); self.config.error(&r);
Err(anyhow::Error::new(r)) Err(anyhow::Error::new(r))
} }
} }
@ -288,11 +288,11 @@ impl<T: CliConfig> Cli<T> {
let result = request.send().await; let result = request.send().await;
match result { match result {
Ok(r) => { Ok(r) => {
self.config.item_success(&r); self.config.success_no_item(&r);
Ok(()) Ok(())
} }
Err(r) => { Err(r) => {
self.config.item_error(&r); self.config.error(&r);
Err(anyhow::Error::new(r)) Err(anyhow::Error::new(r))
} }
} }
@ -319,11 +319,11 @@ impl<T: CliConfig> Cli<T> {
let result = request.send().await; let result = request.send().await;
match result { match result {
Ok(r) => { Ok(r) => {
self.config.item_success(&r); self.config.success_item(&r);
Ok(()) Ok(())
} }
Err(r) => { Err(r) => {
self.config.item_error(&r); self.config.error(&r);
Err(anyhow::Error::new(r)) Err(anyhow::Error::new(r))
} }
} }
@ -331,10 +331,11 @@ impl<T: CliConfig> Cli<T> {
} }
pub trait CliConfig { pub trait CliConfig {
fn item_success<T>(&self, value: &ResponseValue<T>) fn success_item<T>(&self, value: &ResponseValue<T>)
where where
T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug; T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
fn item_error<T>(&self, value: &Error<T>) fn success_no_item(&self, value: &ResponseValue<()>);
fn error<T>(&self, value: &Error<T>)
where where
T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug; T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
fn list_start<T>(&self) fn list_start<T>(&self)