CLI: add an output interface for consumers (#708)
This commit is contained in:
parent
fa0e6c7976
commit
dc5e1f1840
|
@ -102,19 +102,22 @@ impl Generator {
|
||||||
|
|
||||||
let crate_path = syn::TypePath {
|
let crate_path = syn::TypePath {
|
||||||
qself: None,
|
qself: None,
|
||||||
path: syn::parse_str(&crate_name).unwrap(),
|
path: syn::parse_str(crate_name).unwrap(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let code = quote! {
|
let code = quote! {
|
||||||
use #crate_path::*;
|
use #crate_path::*;
|
||||||
|
|
||||||
pub struct Cli<T: CliOverride = ()> {
|
pub struct Cli<T: CliConfig> {
|
||||||
client: Client,
|
client: Client,
|
||||||
over: T,
|
config: T,
|
||||||
}
|
}
|
||||||
impl Cli {
|
impl<T: CliConfig> Cli<T> {
|
||||||
pub fn new(client: Client) -> Self {
|
pub fn new(
|
||||||
Self { client, over: () }
|
client: Client,
|
||||||
|
config: T,
|
||||||
|
) -> Self {
|
||||||
|
Self { client, config }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_command(cmd: CliCommand) -> clap::Command {
|
pub fn get_command(cmd: CliCommand) -> clap::Command {
|
||||||
|
@ -126,26 +129,17 @@ impl Generator {
|
||||||
}
|
}
|
||||||
|
|
||||||
#(#cli_ops)*
|
#(#cli_ops)*
|
||||||
}
|
|
||||||
|
|
||||||
impl<T: CliOverride> Cli<T> {
|
|
||||||
pub fn new_with_override(
|
|
||||||
client: Client,
|
|
||||||
over: T,
|
|
||||||
) -> Self {
|
|
||||||
Self { client, over }
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn execute(
|
pub async fn execute(
|
||||||
&self,
|
&self,
|
||||||
cmd: CliCommand,
|
cmd: CliCommand,
|
||||||
matches: &clap::ArgMatches,
|
matches: &clap::ArgMatches,
|
||||||
) {
|
) -> anyhow::Result<()> {
|
||||||
match cmd {
|
match cmd {
|
||||||
#(
|
#(
|
||||||
CliCommand::#cli_variants => {
|
CliCommand::#cli_variants => {
|
||||||
// TODO ... do something with output
|
// TODO ... do something with output
|
||||||
self.#execute_fns(matches).await;
|
self.#execute_fns(matches).await
|
||||||
}
|
}
|
||||||
)*
|
)*
|
||||||
}
|
}
|
||||||
|
@ -154,12 +148,30 @@ impl Generator {
|
||||||
#(#execute_ops)*
|
#(#execute_ops)*
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait CliOverride {
|
pub trait CliConfig {
|
||||||
|
fn item_success<T>(&self, value: &ResponseValue<T>)
|
||||||
|
where
|
||||||
|
T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
|
||||||
|
fn item_error<T>(&self, value: &Error<T>)
|
||||||
|
where
|
||||||
|
T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
|
||||||
|
|
||||||
|
fn list_start<T>(&self)
|
||||||
|
where
|
||||||
|
T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
|
||||||
|
fn list_item<T>(&self, value: &T)
|
||||||
|
where
|
||||||
|
T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
|
||||||
|
fn list_end_success<T>(&self)
|
||||||
|
where
|
||||||
|
T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
|
||||||
|
fn list_end_error<T>(&self, value: &Error<T>)
|
||||||
|
where
|
||||||
|
T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
|
||||||
|
|
||||||
#(#trait_ops)*
|
#(#trait_ops)*
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CliOverride for () {}
|
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug)]
|
#[derive(Copy, Clone, Debug)]
|
||||||
pub enum CliCommand {
|
pub enum CliCommand {
|
||||||
#(#cli_variants,)*
|
#(#cli_variants,)*
|
||||||
|
@ -216,67 +228,111 @@ impl Generator {
|
||||||
let fn_name = format_ident!("execute_{}", &method.operation_id);
|
let fn_name = format_ident!("execute_{}", &method.operation_id);
|
||||||
let op_name = format_ident!("{}", &method.operation_id);
|
let op_name = format_ident!("{}", &method.operation_id);
|
||||||
|
|
||||||
let (_, success_type) = self.extract_responses(
|
let (_, success_kind) = self.extract_responses(
|
||||||
method,
|
method,
|
||||||
OperationResponseStatus::is_success_or_default,
|
OperationResponseStatus::is_success_or_default,
|
||||||
);
|
);
|
||||||
let (_, error_type) = self.extract_responses(
|
let (_, error_kind) = self.extract_responses(
|
||||||
method,
|
method,
|
||||||
OperationResponseStatus::is_error_or_default,
|
OperationResponseStatus::is_error_or_default,
|
||||||
);
|
);
|
||||||
|
|
||||||
let success_output = match success_type {
|
|
||||||
crate::method::OperationResponseType::Type(_) => {
|
|
||||||
quote! { println!("success\n{:#?}", r) }
|
|
||||||
}
|
|
||||||
crate::method::OperationResponseType::None => {
|
|
||||||
quote! { println!("success\n{:#?}", r) }
|
|
||||||
}
|
|
||||||
crate::method::OperationResponseType::Raw => quote! { todo!() },
|
|
||||||
crate::method::OperationResponseType::Upgrade => quote! { todo!() },
|
|
||||||
};
|
|
||||||
|
|
||||||
let error_output = match error_type {
|
|
||||||
crate::method::OperationResponseType::Type(_) => {
|
|
||||||
quote! { println!("error\n{:#?}", r) }
|
|
||||||
}
|
|
||||||
crate::method::OperationResponseType::None => {
|
|
||||||
quote! { println!("success\n{:#?}", r) }
|
|
||||||
}
|
|
||||||
crate::method::OperationResponseType::Raw => quote! { todo!() },
|
|
||||||
crate::method::OperationResponseType::Upgrade => quote! { todo!() },
|
|
||||||
};
|
|
||||||
|
|
||||||
let execute_and_output = match method.dropshot_paginated {
|
let execute_and_output = match method.dropshot_paginated {
|
||||||
|
// Normal, one-shot API calls.
|
||||||
None => {
|
None => {
|
||||||
|
let success_output = match success_kind {
|
||||||
|
crate::method::OperationResponseKind::Type(_)
|
||||||
|
| crate::method::OperationResponseKind::None => {
|
||||||
|
quote! {
|
||||||
|
{
|
||||||
|
self.config.item_success(&r);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
crate::method::OperationResponseKind::Raw
|
||||||
|
| crate::method::OperationResponseKind::Upgrade => {
|
||||||
|
quote! {
|
||||||
|
{
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let error_output = match error_kind {
|
||||||
|
crate::method::OperationResponseKind::Type(_)
|
||||||
|
| crate::method::OperationResponseKind::None => {
|
||||||
|
quote! {
|
||||||
|
{
|
||||||
|
self.config.item_error(&r);
|
||||||
|
Err(anyhow::Error::new(r))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
crate::method::OperationResponseKind::Raw
|
||||||
|
| crate::method::OperationResponseKind::Upgrade => {
|
||||||
|
quote! {
|
||||||
|
{
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
quote! {
|
quote! {
|
||||||
let result = request.send().await;
|
let result = request.send().await;
|
||||||
|
|
||||||
match result {
|
match result {
|
||||||
Ok(r) => {
|
Ok(r) => #success_output
|
||||||
#success_output
|
Err(r) => #error_output
|
||||||
}
|
|
||||||
Err(r) => {
|
|
||||||
#error_output
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Paginated APIs for which we iterate over each item.
|
||||||
Some(_) => {
|
Some(_) => {
|
||||||
|
let success_type = match success_kind {
|
||||||
|
crate::method::OperationResponseKind::Type(type_id) => {
|
||||||
|
self.type_space.get_type(&type_id).unwrap().ident()
|
||||||
|
}
|
||||||
|
crate::method::OperationResponseKind::None => quote! { () },
|
||||||
|
crate::method::OperationResponseKind::Raw => todo!(),
|
||||||
|
crate::method::OperationResponseKind::Upgrade => todo!(),
|
||||||
|
};
|
||||||
|
let error_output = match error_kind {
|
||||||
|
crate::method::OperationResponseKind::Type(_)
|
||||||
|
| crate::method::OperationResponseKind::None => {
|
||||||
quote! {
|
quote! {
|
||||||
|
{
|
||||||
|
self.config.list_end_error(&r);
|
||||||
|
return Err(anyhow::Error::new(r))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
crate::method::OperationResponseKind::Raw
|
||||||
|
| crate::method::OperationResponseKind::Upgrade => {
|
||||||
|
quote! {
|
||||||
|
{
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
quote! {
|
||||||
|
self.config.list_start::<#success_type>();
|
||||||
|
|
||||||
let mut stream = request.stream();
|
let mut stream = request.stream();
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
match futures::TryStreamExt::try_next(&mut stream).await {
|
match futures::TryStreamExt::try_next(&mut stream).await {
|
||||||
Err(r) => {
|
Err(r) => #error_output
|
||||||
#error_output;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
Ok(None) => {
|
Ok(None) => {
|
||||||
break;
|
self.config.list_end_success::<#success_type>();
|
||||||
|
return Ok(());
|
||||||
}
|
}
|
||||||
Ok(Some(value)) => {
|
Ok(Some(value)) => {
|
||||||
println!("{:#?}", value);
|
self.config.list_item(&value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -286,17 +342,13 @@ impl Generator {
|
||||||
|
|
||||||
let execute_fn = quote! {
|
let execute_fn = quote! {
|
||||||
pub async fn #fn_name(&self, matches: &clap::ArgMatches)
|
pub async fn #fn_name(&self, matches: &clap::ArgMatches)
|
||||||
// ->
|
-> anyhow::Result<()>
|
||||||
// Result<ResponseValue<#success_type>, Error<#error_type>>
|
|
||||||
{
|
{
|
||||||
let mut request = self.client.#op_name();
|
let mut request = self.client.#op_name();
|
||||||
#consumer_args
|
#consumer_args
|
||||||
|
|
||||||
// Call the override function.
|
// Call the override function.
|
||||||
// TODO don't want to unwrap.
|
self.config.#fn_name(matches, &mut request)?;
|
||||||
self.over
|
|
||||||
.#fn_name(matches, &mut request)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
#execute_and_output
|
#execute_and_output
|
||||||
}
|
}
|
||||||
|
@ -311,7 +363,7 @@ impl Generator {
|
||||||
&self,
|
&self,
|
||||||
matches: &clap::ArgMatches,
|
matches: &clap::ArgMatches,
|
||||||
request: &mut builder :: #struct_ident,
|
request: &mut builder :: #struct_ident,
|
||||||
) -> Result<(), String> {
|
) -> anyhow::Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -81,7 +81,7 @@ impl Generator {
|
||||||
|
|
||||||
let crate_path = syn::TypePath {
|
let crate_path = syn::TypePath {
|
||||||
qself: None,
|
qself: None,
|
||||||
path: syn::parse_str(&crate_name).unwrap(),
|
path: syn::parse_str(crate_name).unwrap(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let code = quote! {
|
let code = quote! {
|
||||||
|
@ -295,7 +295,7 @@ impl Generator {
|
||||||
status_code, typ, ..
|
status_code, typ, ..
|
||||||
}| {
|
}| {
|
||||||
let (value_param, value_use) = match typ {
|
let (value_param, value_use) = match typ {
|
||||||
crate::method::OperationResponseType::Type(arg_type_id) => {
|
crate::method::OperationResponseKind::Type(arg_type_id) => {
|
||||||
let arg_type =
|
let arg_type =
|
||||||
self.type_space.get_type(arg_type_id).unwrap();
|
self.type_space.get_type(arg_type_id).unwrap();
|
||||||
let arg_type_ident = arg_type.parameter_ident();
|
let arg_type_ident = arg_type.parameter_ident();
|
||||||
|
@ -309,10 +309,10 @@ impl Generator {
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
crate::method::OperationResponseType::None => {
|
crate::method::OperationResponseKind::None => {
|
||||||
Default::default()
|
Default::default()
|
||||||
}
|
}
|
||||||
crate::method::OperationResponseType::Raw => (
|
crate::method::OperationResponseKind::Raw => (
|
||||||
quote! {
|
quote! {
|
||||||
value: serde_json::Value,
|
value: serde_json::Value,
|
||||||
},
|
},
|
||||||
|
@ -321,7 +321,7 @@ impl Generator {
|
||||||
.json_body(value)
|
.json_body(value)
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
crate::method::OperationResponseType::Upgrade => {
|
crate::method::OperationResponseKind::Upgrade => {
|
||||||
Default::default()
|
Default::default()
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -166,7 +166,7 @@ impl std::fmt::Display for BodyContentType {
|
||||||
Self::OctetStream => "application/octet-stream",
|
Self::OctetStream => "application/octet-stream",
|
||||||
Self::Json => "application/json",
|
Self::Json => "application/json",
|
||||||
Self::FormUrlencoded => "application/x-www-form-urlencoded",
|
Self::FormUrlencoded => "application/x-www-form-urlencoded",
|
||||||
Self::Text(typ) => &typ,
|
Self::Text(typ) => typ,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -174,7 +174,7 @@ impl std::fmt::Display for BodyContentType {
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub(crate) struct OperationResponse {
|
pub(crate) struct OperationResponse {
|
||||||
pub status_code: OperationResponseStatus,
|
pub status_code: OperationResponseStatus,
|
||||||
pub typ: OperationResponseType,
|
pub typ: OperationResponseKind,
|
||||||
// TODO this isn't currently used because dropshot doesn't give us a
|
// TODO this isn't currently used because dropshot doesn't give us a
|
||||||
// particularly useful message here.
|
// particularly useful message here.
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
|
@ -257,27 +257,27 @@ impl PartialOrd for OperationResponseStatus {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone)]
|
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone)]
|
||||||
pub(crate) enum OperationResponseType {
|
pub(crate) enum OperationResponseKind {
|
||||||
Type(TypeId),
|
Type(TypeId),
|
||||||
None,
|
None,
|
||||||
Raw,
|
Raw,
|
||||||
Upgrade,
|
Upgrade,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl OperationResponseType {
|
impl OperationResponseKind {
|
||||||
pub fn into_tokens(self, type_space: &TypeSpace) -> TokenStream {
|
pub fn into_tokens(self, type_space: &TypeSpace) -> TokenStream {
|
||||||
match self {
|
match self {
|
||||||
OperationResponseType::Type(ref type_id) => {
|
OperationResponseKind::Type(ref type_id) => {
|
||||||
let type_name = type_space.get_type(type_id).unwrap().ident();
|
let type_name = type_space.get_type(type_id).unwrap().ident();
|
||||||
quote! { #type_name }
|
quote! { #type_name }
|
||||||
}
|
}
|
||||||
OperationResponseType::None => {
|
OperationResponseKind::None => {
|
||||||
quote! { () }
|
quote! { () }
|
||||||
}
|
}
|
||||||
OperationResponseType::Raw => {
|
OperationResponseKind::Raw => {
|
||||||
quote! { ByteStream }
|
quote! { ByteStream }
|
||||||
}
|
}
|
||||||
OperationResponseType::Upgrade => {
|
OperationResponseKind::Upgrade => {
|
||||||
quote! { reqwest::Upgraded }
|
quote! { reqwest::Upgraded }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -508,13 +508,13 @@ impl Generator {
|
||||||
todo!("media type encoding, no schema: {:#?}", mt);
|
todo!("media type encoding, no schema: {:#?}", mt);
|
||||||
};
|
};
|
||||||
|
|
||||||
OperationResponseType::Type(typ)
|
OperationResponseKind::Type(typ)
|
||||||
} else if dropshot_websocket {
|
} else if dropshot_websocket {
|
||||||
OperationResponseType::Upgrade
|
OperationResponseKind::Upgrade
|
||||||
} else if response.content.first().is_some() {
|
} else if response.content.first().is_some() {
|
||||||
OperationResponseType::Raw
|
OperationResponseKind::Raw
|
||||||
} else {
|
} else {
|
||||||
OperationResponseType::None
|
OperationResponseKind::None
|
||||||
};
|
};
|
||||||
|
|
||||||
// See if there's a status code that covers success cases.
|
// See if there's a status code that covers success cases.
|
||||||
|
@ -548,7 +548,7 @@ impl Generator {
|
||||||
if !success {
|
if !success {
|
||||||
responses.push(OperationResponse {
|
responses.push(OperationResponse {
|
||||||
status_code: OperationResponseStatus::Range(2),
|
status_code: OperationResponseStatus::Range(2),
|
||||||
typ: OperationResponseType::Raw,
|
typ: OperationResponseKind::Raw,
|
||||||
description: None,
|
description: None,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -557,7 +557,7 @@ impl Generator {
|
||||||
if dropshot_websocket {
|
if dropshot_websocket {
|
||||||
responses.push(OperationResponse {
|
responses.push(OperationResponse {
|
||||||
status_code: OperationResponseStatus::Code(101),
|
status_code: OperationResponseStatus::Code(101),
|
||||||
typ: OperationResponseType::Upgrade,
|
typ: OperationResponseKind::Upgrade,
|
||||||
description: None,
|
description: None,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -1019,22 +1019,22 @@ impl Generator {
|
||||||
};
|
};
|
||||||
|
|
||||||
let decode = match &response.typ {
|
let decode = match &response.typ {
|
||||||
OperationResponseType::Type(_) => {
|
OperationResponseKind::Type(_) => {
|
||||||
quote! {
|
quote! {
|
||||||
ResponseValue::from_response(#response_ident).await
|
ResponseValue::from_response(#response_ident).await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
OperationResponseType::None => {
|
OperationResponseKind::None => {
|
||||||
quote! {
|
quote! {
|
||||||
Ok(ResponseValue::empty(#response_ident))
|
Ok(ResponseValue::empty(#response_ident))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
OperationResponseType::Raw => {
|
OperationResponseKind::Raw => {
|
||||||
quote! {
|
quote! {
|
||||||
Ok(ResponseValue::stream(#response_ident))
|
Ok(ResponseValue::stream(#response_ident))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
OperationResponseType::Upgrade => {
|
OperationResponseKind::Upgrade => {
|
||||||
quote! {
|
quote! {
|
||||||
ResponseValue::upgrade(#response_ident).await
|
ResponseValue::upgrade(#response_ident).await
|
||||||
}
|
}
|
||||||
|
@ -1068,7 +1068,7 @@ impl Generator {
|
||||||
};
|
};
|
||||||
|
|
||||||
let decode = match &response.typ {
|
let decode = match &response.typ {
|
||||||
OperationResponseType::Type(_) => {
|
OperationResponseKind::Type(_) => {
|
||||||
quote! {
|
quote! {
|
||||||
Err(Error::ErrorResponse(
|
Err(Error::ErrorResponse(
|
||||||
ResponseValue::from_response(#response_ident)
|
ResponseValue::from_response(#response_ident)
|
||||||
|
@ -1076,21 +1076,21 @@ impl Generator {
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
OperationResponseType::None => {
|
OperationResponseKind::None => {
|
||||||
quote! {
|
quote! {
|
||||||
Err(Error::ErrorResponse(
|
Err(Error::ErrorResponse(
|
||||||
ResponseValue::empty(#response_ident)
|
ResponseValue::empty(#response_ident)
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
OperationResponseType::Raw => {
|
OperationResponseKind::Raw => {
|
||||||
quote! {
|
quote! {
|
||||||
Err(Error::ErrorResponse(
|
Err(Error::ErrorResponse(
|
||||||
ResponseValue::stream(#response_ident)
|
ResponseValue::stream(#response_ident)
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
OperationResponseType::Upgrade => {
|
OperationResponseKind::Upgrade => {
|
||||||
if response.status_code
|
if response.status_code
|
||||||
== OperationResponseStatus::Default
|
== OperationResponseStatus::Default
|
||||||
{
|
{
|
||||||
|
@ -1109,8 +1109,8 @@ impl Generator {
|
||||||
|
|
||||||
let accept_header = matches!(
|
let accept_header = matches!(
|
||||||
(&response_type, &error_type),
|
(&response_type, &error_type),
|
||||||
(OperationResponseType::Type(_), _)
|
(OperationResponseKind::Type(_), _)
|
||||||
| (OperationResponseType::None, OperationResponseType::Type(_))
|
| (OperationResponseKind::None, OperationResponseKind::Type(_))
|
||||||
)
|
)
|
||||||
.then(|| {
|
.then(|| {
|
||||||
quote! {
|
quote! {
|
||||||
|
@ -1233,7 +1233,7 @@ impl Generator {
|
||||||
&self,
|
&self,
|
||||||
method: &'a OperationMethod,
|
method: &'a OperationMethod,
|
||||||
filter: fn(&OperationResponseStatus) -> bool,
|
filter: fn(&OperationResponseStatus) -> bool,
|
||||||
) -> (Vec<&'a OperationResponse>, OperationResponseType) {
|
) -> (Vec<&'a OperationResponse>, OperationResponseKind) {
|
||||||
let mut response_items = method
|
let mut response_items = method
|
||||||
.responses
|
.responses
|
||||||
.iter()
|
.iter()
|
||||||
|
@ -1273,7 +1273,7 @@ impl Generator {
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.next()
|
.next()
|
||||||
// TODO should this be OperationResponseType::Raw?
|
// TODO should this be OperationResponseType::Raw?
|
||||||
.unwrap_or(OperationResponseType::None);
|
.unwrap_or(OperationResponseKind::None);
|
||||||
(response_items, response_type)
|
(response_items, response_type)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1333,7 +1333,7 @@ impl Generator {
|
||||||
(
|
(
|
||||||
OperationResponseStatus::Code(200..=299)
|
OperationResponseStatus::Code(200..=299)
|
||||||
| OperationResponseStatus::Range(2),
|
| OperationResponseStatus::Range(2),
|
||||||
OperationResponseType::Type(type_id),
|
OperationResponseKind::Type(type_id),
|
||||||
) => Some(type_id),
|
) => Some(type_id),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
use crate::buildomat_builder::*;
|
use crate::buildomat_builder::*;
|
||||||
pub struct Cli<T: CliOverride = ()> {
|
pub struct Cli<T: CliConfig> {
|
||||||
client: Client,
|
client: Client,
|
||||||
over: T,
|
config: T,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Cli {
|
impl<T: CliConfig> Cli<T> {
|
||||||
pub fn new(client: Client) -> Self {
|
pub fn new(client: Client, config: T) -> Self {
|
||||||
Self { client, over: () }
|
Self { client, config }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_command(cmd: CliCommand) -> clap::Command {
|
pub fn get_command(cmd: CliCommand) -> clap::Command {
|
||||||
|
@ -315,140 +315,102 @@ impl Cli {
|
||||||
pub fn cli_workers_recycle() -> clap::Command {
|
pub fn cli_workers_recycle() -> clap::Command {
|
||||||
clap::Command::new("")
|
clap::Command::new("")
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
impl<T: CliOverride> Cli<T> {
|
pub async fn execute(&self, cmd: CliCommand, matches: &clap::ArgMatches) -> anyhow::Result<()> {
|
||||||
pub fn new_with_override(client: Client, over: T) -> Self {
|
|
||||||
Self { client, over }
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn execute(&self, cmd: CliCommand, matches: &clap::ArgMatches) {
|
|
||||||
match cmd {
|
match cmd {
|
||||||
CliCommand::ControlHold => {
|
CliCommand::ControlHold => self.execute_control_hold(matches).await,
|
||||||
self.execute_control_hold(matches).await;
|
CliCommand::ControlResume => self.execute_control_resume(matches).await,
|
||||||
}
|
CliCommand::TaskGet => self.execute_task_get(matches).await,
|
||||||
CliCommand::ControlResume => {
|
CliCommand::TasksGet => self.execute_tasks_get(matches).await,
|
||||||
self.execute_control_resume(matches).await;
|
CliCommand::TaskSubmit => self.execute_task_submit(matches).await,
|
||||||
}
|
CliCommand::TaskEventsGet => self.execute_task_events_get(matches).await,
|
||||||
CliCommand::TaskGet => {
|
CliCommand::TaskOutputsGet => self.execute_task_outputs_get(matches).await,
|
||||||
self.execute_task_get(matches).await;
|
CliCommand::TaskOutputDownload => self.execute_task_output_download(matches).await,
|
||||||
}
|
CliCommand::UserCreate => self.execute_user_create(matches).await,
|
||||||
CliCommand::TasksGet => {
|
CliCommand::Whoami => self.execute_whoami(matches).await,
|
||||||
self.execute_tasks_get(matches).await;
|
CliCommand::WhoamiPutName => self.execute_whoami_put_name(matches).await,
|
||||||
}
|
CliCommand::WorkerBootstrap => self.execute_worker_bootstrap(matches).await,
|
||||||
CliCommand::TaskSubmit => {
|
CliCommand::WorkerPing => self.execute_worker_ping(matches).await,
|
||||||
self.execute_task_submit(matches).await;
|
CliCommand::WorkerTaskAppend => self.execute_worker_task_append(matches).await,
|
||||||
}
|
|
||||||
CliCommand::TaskEventsGet => {
|
|
||||||
self.execute_task_events_get(matches).await;
|
|
||||||
}
|
|
||||||
CliCommand::TaskOutputsGet => {
|
|
||||||
self.execute_task_outputs_get(matches).await;
|
|
||||||
}
|
|
||||||
CliCommand::TaskOutputDownload => {
|
|
||||||
self.execute_task_output_download(matches).await;
|
|
||||||
}
|
|
||||||
CliCommand::UserCreate => {
|
|
||||||
self.execute_user_create(matches).await;
|
|
||||||
}
|
|
||||||
CliCommand::Whoami => {
|
|
||||||
self.execute_whoami(matches).await;
|
|
||||||
}
|
|
||||||
CliCommand::WhoamiPutName => {
|
|
||||||
self.execute_whoami_put_name(matches).await;
|
|
||||||
}
|
|
||||||
CliCommand::WorkerBootstrap => {
|
|
||||||
self.execute_worker_bootstrap(matches).await;
|
|
||||||
}
|
|
||||||
CliCommand::WorkerPing => {
|
|
||||||
self.execute_worker_ping(matches).await;
|
|
||||||
}
|
|
||||||
CliCommand::WorkerTaskAppend => {
|
|
||||||
self.execute_worker_task_append(matches).await;
|
|
||||||
}
|
|
||||||
CliCommand::WorkerTaskUploadChunk => {
|
CliCommand::WorkerTaskUploadChunk => {
|
||||||
self.execute_worker_task_upload_chunk(matches).await;
|
self.execute_worker_task_upload_chunk(matches).await
|
||||||
}
|
|
||||||
CliCommand::WorkerTaskComplete => {
|
|
||||||
self.execute_worker_task_complete(matches).await;
|
|
||||||
}
|
|
||||||
CliCommand::WorkerTaskAddOutput => {
|
|
||||||
self.execute_worker_task_add_output(matches).await;
|
|
||||||
}
|
|
||||||
CliCommand::WorkersList => {
|
|
||||||
self.execute_workers_list(matches).await;
|
|
||||||
}
|
|
||||||
CliCommand::WorkersRecycle => {
|
|
||||||
self.execute_workers_recycle(matches).await;
|
|
||||||
}
|
}
|
||||||
|
CliCommand::WorkerTaskComplete => self.execute_worker_task_complete(matches).await,
|
||||||
|
CliCommand::WorkerTaskAddOutput => self.execute_worker_task_add_output(matches).await,
|
||||||
|
CliCommand::WorkersList => self.execute_workers_list(matches).await,
|
||||||
|
CliCommand::WorkersRecycle => self.execute_workers_recycle(matches).await,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn execute_control_hold(&self, matches: &clap::ArgMatches) {
|
pub async fn execute_control_hold(&self, matches: &clap::ArgMatches) -> anyhow::Result<()> {
|
||||||
let mut request = self.client.control_hold();
|
let mut request = self.client.control_hold();
|
||||||
self.over
|
self.config.execute_control_hold(matches, &mut request)?;
|
||||||
.execute_control_hold(matches, &mut request)
|
|
||||||
.unwrap();
|
|
||||||
let result = request.send().await;
|
let result = request.send().await;
|
||||||
match result {
|
match result {
|
||||||
Ok(r) => {
|
Ok(r) => {
|
||||||
println!("success\n{:#?}", r)
|
self.config.item_success(&r);
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
Err(r) => {
|
Err(r) => {
|
||||||
println!("success\n{:#?}", r)
|
self.config.item_error(&r);
|
||||||
|
Err(anyhow::Error::new(r))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn execute_control_resume(&self, matches: &clap::ArgMatches) {
|
pub async fn execute_control_resume(&self, matches: &clap::ArgMatches) -> anyhow::Result<()> {
|
||||||
let mut request = self.client.control_resume();
|
let mut request = self.client.control_resume();
|
||||||
self.over
|
self.config.execute_control_resume(matches, &mut request)?;
|
||||||
.execute_control_resume(matches, &mut request)
|
|
||||||
.unwrap();
|
|
||||||
let result = request.send().await;
|
let result = request.send().await;
|
||||||
match result {
|
match result {
|
||||||
Ok(r) => {
|
Ok(r) => {
|
||||||
println!("success\n{:#?}", r)
|
self.config.item_success(&r);
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
Err(r) => {
|
Err(r) => {
|
||||||
println!("success\n{:#?}", r)
|
self.config.item_error(&r);
|
||||||
|
Err(anyhow::Error::new(r))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn execute_task_get(&self, matches: &clap::ArgMatches) {
|
pub async fn execute_task_get(&self, matches: &clap::ArgMatches) -> anyhow::Result<()> {
|
||||||
let mut request = self.client.task_get();
|
let mut request = self.client.task_get();
|
||||||
if let Some(value) = matches.get_one::<String>("task") {
|
if let Some(value) = matches.get_one::<String>("task") {
|
||||||
request = request.task(value.clone());
|
request = request.task(value.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
self.over.execute_task_get(matches, &mut request).unwrap();
|
self.config.execute_task_get(matches, &mut request)?;
|
||||||
let result = request.send().await;
|
let result = request.send().await;
|
||||||
match result {
|
match result {
|
||||||
Ok(r) => {
|
Ok(r) => {
|
||||||
println!("success\n{:#?}", r)
|
self.config.item_success(&r);
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
Err(r) => {
|
Err(r) => {
|
||||||
println!("success\n{:#?}", r)
|
self.config.item_error(&r);
|
||||||
|
Err(anyhow::Error::new(r))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn execute_tasks_get(&self, matches: &clap::ArgMatches) {
|
pub async fn execute_tasks_get(&self, matches: &clap::ArgMatches) -> anyhow::Result<()> {
|
||||||
let mut request = self.client.tasks_get();
|
let mut request = self.client.tasks_get();
|
||||||
self.over.execute_tasks_get(matches, &mut request).unwrap();
|
self.config.execute_tasks_get(matches, &mut request)?;
|
||||||
let result = request.send().await;
|
let result = request.send().await;
|
||||||
match result {
|
match result {
|
||||||
Ok(r) => {
|
Ok(r) => {
|
||||||
println!("success\n{:#?}", r)
|
self.config.item_success(&r);
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
Err(r) => {
|
Err(r) => {
|
||||||
println!("success\n{:#?}", r)
|
self.config.item_error(&r);
|
||||||
|
Err(anyhow::Error::new(r))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn execute_task_submit(&self, matches: &clap::ArgMatches) {
|
pub async fn execute_task_submit(&self, matches: &clap::ArgMatches) -> anyhow::Result<()> {
|
||||||
let mut request = self.client.task_submit();
|
let mut request = self.client.task_submit();
|
||||||
if let Some(value) = matches.get_one::<String>("name") {
|
if let Some(value) = matches.get_one::<String>("name") {
|
||||||
request = request.body_map(|body| body.name(value.clone()))
|
request = request.body_map(|body| body.name(value.clone()))
|
||||||
|
@ -464,21 +426,21 @@ impl<T: CliOverride> Cli<T> {
|
||||||
request = request.body(body_value);
|
request = request.body(body_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.over
|
self.config.execute_task_submit(matches, &mut request)?;
|
||||||
.execute_task_submit(matches, &mut request)
|
|
||||||
.unwrap();
|
|
||||||
let result = request.send().await;
|
let result = request.send().await;
|
||||||
match result {
|
match result {
|
||||||
Ok(r) => {
|
Ok(r) => {
|
||||||
println!("success\n{:#?}", r)
|
self.config.item_success(&r);
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
Err(r) => {
|
Err(r) => {
|
||||||
println!("success\n{:#?}", r)
|
self.config.item_error(&r);
|
||||||
|
Err(anyhow::Error::new(r))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn execute_task_events_get(&self, matches: &clap::ArgMatches) {
|
pub async fn execute_task_events_get(&self, matches: &clap::ArgMatches) -> anyhow::Result<()> {
|
||||||
let mut request = self.client.task_events_get();
|
let mut request = self.client.task_events_get();
|
||||||
if let Some(value) = matches.get_one::<u32>("minseq") {
|
if let Some(value) = matches.get_one::<u32>("minseq") {
|
||||||
request = request.minseq(value.clone());
|
request = request.minseq(value.clone());
|
||||||
|
@ -488,41 +450,45 @@ impl<T: CliOverride> Cli<T> {
|
||||||
request = request.task(value.clone());
|
request = request.task(value.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
self.over
|
self.config.execute_task_events_get(matches, &mut request)?;
|
||||||
.execute_task_events_get(matches, &mut request)
|
|
||||||
.unwrap();
|
|
||||||
let result = request.send().await;
|
let result = request.send().await;
|
||||||
match result {
|
match result {
|
||||||
Ok(r) => {
|
Ok(r) => {
|
||||||
println!("success\n{:#?}", r)
|
self.config.item_success(&r);
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
Err(r) => {
|
Err(r) => {
|
||||||
println!("success\n{:#?}", r)
|
self.config.item_error(&r);
|
||||||
|
Err(anyhow::Error::new(r))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn execute_task_outputs_get(&self, matches: &clap::ArgMatches) {
|
pub async fn execute_task_outputs_get(&self, matches: &clap::ArgMatches) -> anyhow::Result<()> {
|
||||||
let mut request = self.client.task_outputs_get();
|
let mut request = self.client.task_outputs_get();
|
||||||
if let Some(value) = matches.get_one::<String>("task") {
|
if let Some(value) = matches.get_one::<String>("task") {
|
||||||
request = request.task(value.clone());
|
request = request.task(value.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
self.over
|
self.config
|
||||||
.execute_task_outputs_get(matches, &mut request)
|
.execute_task_outputs_get(matches, &mut request)?;
|
||||||
.unwrap();
|
|
||||||
let result = request.send().await;
|
let result = request.send().await;
|
||||||
match result {
|
match result {
|
||||||
Ok(r) => {
|
Ok(r) => {
|
||||||
println!("success\n{:#?}", r)
|
self.config.item_success(&r);
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
Err(r) => {
|
Err(r) => {
|
||||||
println!("success\n{:#?}", r)
|
self.config.item_error(&r);
|
||||||
|
Err(anyhow::Error::new(r))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn execute_task_output_download(&self, matches: &clap::ArgMatches) {
|
pub async fn execute_task_output_download(
|
||||||
|
&self,
|
||||||
|
matches: &clap::ArgMatches,
|
||||||
|
) -> anyhow::Result<()> {
|
||||||
let mut request = self.client.task_output_download();
|
let mut request = self.client.task_output_download();
|
||||||
if let Some(value) = matches.get_one::<String>("output") {
|
if let Some(value) = matches.get_one::<String>("output") {
|
||||||
request = request.output(value.clone());
|
request = request.output(value.clone());
|
||||||
|
@ -532,21 +498,21 @@ impl<T: CliOverride> Cli<T> {
|
||||||
request = request.task(value.clone());
|
request = request.task(value.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
self.over
|
self.config
|
||||||
.execute_task_output_download(matches, &mut request)
|
.execute_task_output_download(matches, &mut request)?;
|
||||||
.unwrap();
|
|
||||||
let result = request.send().await;
|
let result = request.send().await;
|
||||||
match result {
|
match result {
|
||||||
Ok(r) => {
|
Ok(r) => {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
Err(r) => {
|
Err(r) => {
|
||||||
println!("success\n{:#?}", r)
|
self.config.item_error(&r);
|
||||||
|
Err(anyhow::Error::new(r))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn execute_user_create(&self, matches: &clap::ArgMatches) {
|
pub async fn execute_user_create(&self, matches: &clap::ArgMatches) -> anyhow::Result<()> {
|
||||||
let mut request = self.client.user_create();
|
let mut request = self.client.user_create();
|
||||||
if let Some(value) = matches.get_one::<String>("name") {
|
if let Some(value) = matches.get_one::<String>("name") {
|
||||||
request = request.body_map(|body| body.name(value.clone()))
|
request = request.body_map(|body| body.name(value.clone()))
|
||||||
|
@ -558,51 +524,53 @@ impl<T: CliOverride> Cli<T> {
|
||||||
request = request.body(body_value);
|
request = request.body(body_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.over
|
self.config.execute_user_create(matches, &mut request)?;
|
||||||
.execute_user_create(matches, &mut request)
|
|
||||||
.unwrap();
|
|
||||||
let result = request.send().await;
|
let result = request.send().await;
|
||||||
match result {
|
match result {
|
||||||
Ok(r) => {
|
Ok(r) => {
|
||||||
println!("success\n{:#?}", r)
|
self.config.item_success(&r);
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
Err(r) => {
|
Err(r) => {
|
||||||
println!("success\n{:#?}", r)
|
self.config.item_error(&r);
|
||||||
|
Err(anyhow::Error::new(r))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn execute_whoami(&self, matches: &clap::ArgMatches) {
|
pub async fn execute_whoami(&self, matches: &clap::ArgMatches) -> anyhow::Result<()> {
|
||||||
let mut request = self.client.whoami();
|
let mut request = self.client.whoami();
|
||||||
self.over.execute_whoami(matches, &mut request).unwrap();
|
self.config.execute_whoami(matches, &mut request)?;
|
||||||
let result = request.send().await;
|
let result = request.send().await;
|
||||||
match result {
|
match result {
|
||||||
Ok(r) => {
|
Ok(r) => {
|
||||||
println!("success\n{:#?}", r)
|
self.config.item_success(&r);
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
Err(r) => {
|
Err(r) => {
|
||||||
println!("success\n{:#?}", r)
|
self.config.item_error(&r);
|
||||||
|
Err(anyhow::Error::new(r))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn execute_whoami_put_name(&self, matches: &clap::ArgMatches) {
|
pub async fn execute_whoami_put_name(&self, matches: &clap::ArgMatches) -> anyhow::Result<()> {
|
||||||
let mut request = self.client.whoami_put_name();
|
let mut request = self.client.whoami_put_name();
|
||||||
self.over
|
self.config.execute_whoami_put_name(matches, &mut request)?;
|
||||||
.execute_whoami_put_name(matches, &mut request)
|
|
||||||
.unwrap();
|
|
||||||
let result = request.send().await;
|
let result = request.send().await;
|
||||||
match result {
|
match result {
|
||||||
Ok(r) => {
|
Ok(r) => {
|
||||||
println!("success\n{:#?}", r)
|
self.config.item_success(&r);
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
Err(r) => {
|
Err(r) => {
|
||||||
println!("success\n{:#?}", r)
|
self.config.item_error(&r);
|
||||||
|
Err(anyhow::Error::new(r))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn execute_worker_bootstrap(&self, matches: &clap::ArgMatches) {
|
pub async fn execute_worker_bootstrap(&self, matches: &clap::ArgMatches) -> anyhow::Result<()> {
|
||||||
let mut request = self.client.worker_bootstrap();
|
let mut request = self.client.worker_bootstrap();
|
||||||
if let Some(value) = matches.get_one::<String>("bootstrap") {
|
if let Some(value) = matches.get_one::<String>("bootstrap") {
|
||||||
request = request.body_map(|body| body.bootstrap(value.clone()))
|
request = request.body_map(|body| body.bootstrap(value.clone()))
|
||||||
|
@ -618,37 +586,41 @@ impl<T: CliOverride> Cli<T> {
|
||||||
request = request.body(body_value);
|
request = request.body(body_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.over
|
self.config
|
||||||
.execute_worker_bootstrap(matches, &mut request)
|
.execute_worker_bootstrap(matches, &mut request)?;
|
||||||
.unwrap();
|
|
||||||
let result = request.send().await;
|
let result = request.send().await;
|
||||||
match result {
|
match result {
|
||||||
Ok(r) => {
|
Ok(r) => {
|
||||||
println!("success\n{:#?}", r)
|
self.config.item_success(&r);
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
Err(r) => {
|
Err(r) => {
|
||||||
println!("success\n{:#?}", r)
|
self.config.item_error(&r);
|
||||||
|
Err(anyhow::Error::new(r))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn execute_worker_ping(&self, matches: &clap::ArgMatches) {
|
pub async fn execute_worker_ping(&self, matches: &clap::ArgMatches) -> anyhow::Result<()> {
|
||||||
let mut request = self.client.worker_ping();
|
let mut request = self.client.worker_ping();
|
||||||
self.over
|
self.config.execute_worker_ping(matches, &mut request)?;
|
||||||
.execute_worker_ping(matches, &mut request)
|
|
||||||
.unwrap();
|
|
||||||
let result = request.send().await;
|
let result = request.send().await;
|
||||||
match result {
|
match result {
|
||||||
Ok(r) => {
|
Ok(r) => {
|
||||||
println!("success\n{:#?}", r)
|
self.config.item_success(&r);
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
Err(r) => {
|
Err(r) => {
|
||||||
println!("success\n{:#?}", r)
|
self.config.item_error(&r);
|
||||||
|
Err(anyhow::Error::new(r))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn execute_worker_task_append(&self, matches: &clap::ArgMatches) {
|
pub async fn execute_worker_task_append(
|
||||||
|
&self,
|
||||||
|
matches: &clap::ArgMatches,
|
||||||
|
) -> anyhow::Result<()> {
|
||||||
let mut request = self.client.worker_task_append();
|
let mut request = self.client.worker_task_append();
|
||||||
if let Some(value) = matches.get_one::<String>("payload") {
|
if let Some(value) = matches.get_one::<String>("payload") {
|
||||||
request = request.body_map(|body| body.payload(value.clone()))
|
request = request.body_map(|body| body.payload(value.clone()))
|
||||||
|
@ -672,41 +644,49 @@ impl<T: CliOverride> Cli<T> {
|
||||||
request = request.body(body_value);
|
request = request.body(body_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.over
|
self.config
|
||||||
.execute_worker_task_append(matches, &mut request)
|
.execute_worker_task_append(matches, &mut request)?;
|
||||||
.unwrap();
|
|
||||||
let result = request.send().await;
|
let result = request.send().await;
|
||||||
match result {
|
match result {
|
||||||
Ok(r) => {
|
Ok(r) => {
|
||||||
println!("success\n{:#?}", r)
|
self.config.item_success(&r);
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
Err(r) => {
|
Err(r) => {
|
||||||
println!("success\n{:#?}", r)
|
self.config.item_error(&r);
|
||||||
|
Err(anyhow::Error::new(r))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn execute_worker_task_upload_chunk(&self, matches: &clap::ArgMatches) {
|
pub async fn execute_worker_task_upload_chunk(
|
||||||
|
&self,
|
||||||
|
matches: &clap::ArgMatches,
|
||||||
|
) -> anyhow::Result<()> {
|
||||||
let mut request = self.client.worker_task_upload_chunk();
|
let mut request = self.client.worker_task_upload_chunk();
|
||||||
if let Some(value) = matches.get_one::<String>("task") {
|
if let Some(value) = matches.get_one::<String>("task") {
|
||||||
request = request.task(value.clone());
|
request = request.task(value.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
self.over
|
self.config
|
||||||
.execute_worker_task_upload_chunk(matches, &mut request)
|
.execute_worker_task_upload_chunk(matches, &mut request)?;
|
||||||
.unwrap();
|
|
||||||
let result = request.send().await;
|
let result = request.send().await;
|
||||||
match result {
|
match result {
|
||||||
Ok(r) => {
|
Ok(r) => {
|
||||||
println!("success\n{:#?}", r)
|
self.config.item_success(&r);
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
Err(r) => {
|
Err(r) => {
|
||||||
println!("success\n{:#?}", r)
|
self.config.item_error(&r);
|
||||||
|
Err(anyhow::Error::new(r))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn execute_worker_task_complete(&self, matches: &clap::ArgMatches) {
|
pub async fn execute_worker_task_complete(
|
||||||
|
&self,
|
||||||
|
matches: &clap::ArgMatches,
|
||||||
|
) -> anyhow::Result<()> {
|
||||||
let mut request = self.client.worker_task_complete();
|
let mut request = self.client.worker_task_complete();
|
||||||
if let Some(value) = matches.get_one::<bool>("failed") {
|
if let Some(value) = matches.get_one::<bool>("failed") {
|
||||||
request = request.body_map(|body| body.failed(value.clone()))
|
request = request.body_map(|body| body.failed(value.clone()))
|
||||||
|
@ -722,21 +702,25 @@ impl<T: CliOverride> Cli<T> {
|
||||||
request = request.body(body_value);
|
request = request.body(body_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.over
|
self.config
|
||||||
.execute_worker_task_complete(matches, &mut request)
|
.execute_worker_task_complete(matches, &mut request)?;
|
||||||
.unwrap();
|
|
||||||
let result = request.send().await;
|
let result = request.send().await;
|
||||||
match result {
|
match result {
|
||||||
Ok(r) => {
|
Ok(r) => {
|
||||||
println!("success\n{:#?}", r)
|
self.config.item_success(&r);
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
Err(r) => {
|
Err(r) => {
|
||||||
println!("success\n{:#?}", r)
|
self.config.item_error(&r);
|
||||||
|
Err(anyhow::Error::new(r))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn execute_worker_task_add_output(&self, matches: &clap::ArgMatches) {
|
pub async fn execute_worker_task_add_output(
|
||||||
|
&self,
|
||||||
|
matches: &clap::ArgMatches,
|
||||||
|
) -> anyhow::Result<()> {
|
||||||
let mut request = self.client.worker_task_add_output();
|
let mut request = self.client.worker_task_add_output();
|
||||||
if let Some(value) = matches.get_one::<String>("path") {
|
if let Some(value) = matches.get_one::<String>("path") {
|
||||||
request = request.body_map(|body| body.path(value.clone()))
|
request = request.body_map(|body| body.path(value.clone()))
|
||||||
|
@ -756,59 +740,78 @@ impl<T: CliOverride> Cli<T> {
|
||||||
request = request.body(body_value);
|
request = request.body(body_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.over
|
self.config
|
||||||
.execute_worker_task_add_output(matches, &mut request)
|
.execute_worker_task_add_output(matches, &mut request)?;
|
||||||
.unwrap();
|
|
||||||
let result = request.send().await;
|
let result = request.send().await;
|
||||||
match result {
|
match result {
|
||||||
Ok(r) => {
|
Ok(r) => {
|
||||||
println!("success\n{:#?}", r)
|
self.config.item_success(&r);
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
Err(r) => {
|
Err(r) => {
|
||||||
println!("success\n{:#?}", r)
|
self.config.item_error(&r);
|
||||||
|
Err(anyhow::Error::new(r))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn execute_workers_list(&self, matches: &clap::ArgMatches) {
|
pub async fn execute_workers_list(&self, matches: &clap::ArgMatches) -> anyhow::Result<()> {
|
||||||
let mut request = self.client.workers_list();
|
let mut request = self.client.workers_list();
|
||||||
self.over
|
self.config.execute_workers_list(matches, &mut request)?;
|
||||||
.execute_workers_list(matches, &mut request)
|
|
||||||
.unwrap();
|
|
||||||
let result = request.send().await;
|
let result = request.send().await;
|
||||||
match result {
|
match result {
|
||||||
Ok(r) => {
|
Ok(r) => {
|
||||||
println!("success\n{:#?}", r)
|
self.config.item_success(&r);
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
Err(r) => {
|
Err(r) => {
|
||||||
println!("success\n{:#?}", r)
|
self.config.item_error(&r);
|
||||||
|
Err(anyhow::Error::new(r))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn execute_workers_recycle(&self, matches: &clap::ArgMatches) {
|
pub async fn execute_workers_recycle(&self, matches: &clap::ArgMatches) -> anyhow::Result<()> {
|
||||||
let mut request = self.client.workers_recycle();
|
let mut request = self.client.workers_recycle();
|
||||||
self.over
|
self.config.execute_workers_recycle(matches, &mut request)?;
|
||||||
.execute_workers_recycle(matches, &mut request)
|
|
||||||
.unwrap();
|
|
||||||
let result = request.send().await;
|
let result = request.send().await;
|
||||||
match result {
|
match result {
|
||||||
Ok(r) => {
|
Ok(r) => {
|
||||||
println!("success\n{:#?}", r)
|
self.config.item_success(&r);
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
Err(r) => {
|
Err(r) => {
|
||||||
println!("success\n{:#?}", r)
|
self.config.item_error(&r);
|
||||||
|
Err(anyhow::Error::new(r))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait CliOverride {
|
pub trait CliConfig {
|
||||||
|
fn item_success<T>(&self, value: &ResponseValue<T>)
|
||||||
|
where
|
||||||
|
T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
|
||||||
|
fn item_error<T>(&self, value: &Error<T>)
|
||||||
|
where
|
||||||
|
T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
|
||||||
|
fn list_start<T>(&self)
|
||||||
|
where
|
||||||
|
T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
|
||||||
|
fn list_item<T>(&self, value: &T)
|
||||||
|
where
|
||||||
|
T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
|
||||||
|
fn list_end_success<T>(&self)
|
||||||
|
where
|
||||||
|
T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
|
||||||
|
fn list_end_error<T>(&self, value: &Error<T>)
|
||||||
|
where
|
||||||
|
T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
|
||||||
fn execute_control_hold(
|
fn execute_control_hold(
|
||||||
&self,
|
&self,
|
||||||
matches: &clap::ArgMatches,
|
matches: &clap::ArgMatches,
|
||||||
request: &mut builder::ControlHold,
|
request: &mut builder::ControlHold,
|
||||||
) -> Result<(), String> {
|
) -> anyhow::Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -816,7 +819,7 @@ pub trait CliOverride {
|
||||||
&self,
|
&self,
|
||||||
matches: &clap::ArgMatches,
|
matches: &clap::ArgMatches,
|
||||||
request: &mut builder::ControlResume,
|
request: &mut builder::ControlResume,
|
||||||
) -> Result<(), String> {
|
) -> anyhow::Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -824,7 +827,7 @@ pub trait CliOverride {
|
||||||
&self,
|
&self,
|
||||||
matches: &clap::ArgMatches,
|
matches: &clap::ArgMatches,
|
||||||
request: &mut builder::TaskGet,
|
request: &mut builder::TaskGet,
|
||||||
) -> Result<(), String> {
|
) -> anyhow::Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -832,7 +835,7 @@ pub trait CliOverride {
|
||||||
&self,
|
&self,
|
||||||
matches: &clap::ArgMatches,
|
matches: &clap::ArgMatches,
|
||||||
request: &mut builder::TasksGet,
|
request: &mut builder::TasksGet,
|
||||||
) -> Result<(), String> {
|
) -> anyhow::Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -840,7 +843,7 @@ pub trait CliOverride {
|
||||||
&self,
|
&self,
|
||||||
matches: &clap::ArgMatches,
|
matches: &clap::ArgMatches,
|
||||||
request: &mut builder::TaskSubmit,
|
request: &mut builder::TaskSubmit,
|
||||||
) -> Result<(), String> {
|
) -> anyhow::Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -848,7 +851,7 @@ pub trait CliOverride {
|
||||||
&self,
|
&self,
|
||||||
matches: &clap::ArgMatches,
|
matches: &clap::ArgMatches,
|
||||||
request: &mut builder::TaskEventsGet,
|
request: &mut builder::TaskEventsGet,
|
||||||
) -> Result<(), String> {
|
) -> anyhow::Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -856,7 +859,7 @@ pub trait CliOverride {
|
||||||
&self,
|
&self,
|
||||||
matches: &clap::ArgMatches,
|
matches: &clap::ArgMatches,
|
||||||
request: &mut builder::TaskOutputsGet,
|
request: &mut builder::TaskOutputsGet,
|
||||||
) -> Result<(), String> {
|
) -> anyhow::Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -864,7 +867,7 @@ pub trait CliOverride {
|
||||||
&self,
|
&self,
|
||||||
matches: &clap::ArgMatches,
|
matches: &clap::ArgMatches,
|
||||||
request: &mut builder::TaskOutputDownload,
|
request: &mut builder::TaskOutputDownload,
|
||||||
) -> Result<(), String> {
|
) -> anyhow::Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -872,7 +875,7 @@ pub trait CliOverride {
|
||||||
&self,
|
&self,
|
||||||
matches: &clap::ArgMatches,
|
matches: &clap::ArgMatches,
|
||||||
request: &mut builder::UserCreate,
|
request: &mut builder::UserCreate,
|
||||||
) -> Result<(), String> {
|
) -> anyhow::Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -880,7 +883,7 @@ pub trait CliOverride {
|
||||||
&self,
|
&self,
|
||||||
matches: &clap::ArgMatches,
|
matches: &clap::ArgMatches,
|
||||||
request: &mut builder::Whoami,
|
request: &mut builder::Whoami,
|
||||||
) -> Result<(), String> {
|
) -> anyhow::Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -888,7 +891,7 @@ pub trait CliOverride {
|
||||||
&self,
|
&self,
|
||||||
matches: &clap::ArgMatches,
|
matches: &clap::ArgMatches,
|
||||||
request: &mut builder::WhoamiPutName,
|
request: &mut builder::WhoamiPutName,
|
||||||
) -> Result<(), String> {
|
) -> anyhow::Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -896,7 +899,7 @@ pub trait CliOverride {
|
||||||
&self,
|
&self,
|
||||||
matches: &clap::ArgMatches,
|
matches: &clap::ArgMatches,
|
||||||
request: &mut builder::WorkerBootstrap,
|
request: &mut builder::WorkerBootstrap,
|
||||||
) -> Result<(), String> {
|
) -> anyhow::Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -904,7 +907,7 @@ pub trait CliOverride {
|
||||||
&self,
|
&self,
|
||||||
matches: &clap::ArgMatches,
|
matches: &clap::ArgMatches,
|
||||||
request: &mut builder::WorkerPing,
|
request: &mut builder::WorkerPing,
|
||||||
) -> Result<(), String> {
|
) -> anyhow::Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -912,7 +915,7 @@ pub trait CliOverride {
|
||||||
&self,
|
&self,
|
||||||
matches: &clap::ArgMatches,
|
matches: &clap::ArgMatches,
|
||||||
request: &mut builder::WorkerTaskAppend,
|
request: &mut builder::WorkerTaskAppend,
|
||||||
) -> Result<(), String> {
|
) -> anyhow::Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -920,7 +923,7 @@ pub trait CliOverride {
|
||||||
&self,
|
&self,
|
||||||
matches: &clap::ArgMatches,
|
matches: &clap::ArgMatches,
|
||||||
request: &mut builder::WorkerTaskUploadChunk,
|
request: &mut builder::WorkerTaskUploadChunk,
|
||||||
) -> Result<(), String> {
|
) -> anyhow::Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -928,7 +931,7 @@ pub trait CliOverride {
|
||||||
&self,
|
&self,
|
||||||
matches: &clap::ArgMatches,
|
matches: &clap::ArgMatches,
|
||||||
request: &mut builder::WorkerTaskComplete,
|
request: &mut builder::WorkerTaskComplete,
|
||||||
) -> Result<(), String> {
|
) -> anyhow::Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -936,7 +939,7 @@ pub trait CliOverride {
|
||||||
&self,
|
&self,
|
||||||
matches: &clap::ArgMatches,
|
matches: &clap::ArgMatches,
|
||||||
request: &mut builder::WorkerTaskAddOutput,
|
request: &mut builder::WorkerTaskAddOutput,
|
||||||
) -> Result<(), String> {
|
) -> anyhow::Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -944,7 +947,7 @@ pub trait CliOverride {
|
||||||
&self,
|
&self,
|
||||||
matches: &clap::ArgMatches,
|
matches: &clap::ArgMatches,
|
||||||
request: &mut builder::WorkersList,
|
request: &mut builder::WorkersList,
|
||||||
) -> Result<(), String> {
|
) -> anyhow::Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -952,12 +955,11 @@ pub trait CliOverride {
|
||||||
&self,
|
&self,
|
||||||
matches: &clap::ArgMatches,
|
matches: &clap::ArgMatches,
|
||||||
request: &mut builder::WorkersRecycle,
|
request: &mut builder::WorkersRecycle,
|
||||||
) -> Result<(), String> {
|
) -> anyhow::Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CliOverride for () {}
|
|
||||||
#[derive(Copy, Clone, Debug)]
|
#[derive(Copy, Clone, Debug)]
|
||||||
pub enum CliCommand {
|
pub enum CliCommand {
|
||||||
ControlHold,
|
ControlHold,
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
use crate::keeper_builder::*;
|
use crate::keeper_builder::*;
|
||||||
pub struct Cli<T: CliOverride = ()> {
|
pub struct Cli<T: CliConfig> {
|
||||||
client: Client,
|
client: Client,
|
||||||
over: T,
|
config: T,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Cli {
|
impl<T: CliConfig> Cli<T> {
|
||||||
pub fn new(client: Client) -> Self {
|
pub fn new(client: Client, config: T) -> Self {
|
||||||
Self { client, over: () }
|
Self { client, config }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_command(cmd: CliCommand) -> clap::Command {
|
pub fn get_command(cmd: CliCommand) -> clap::Command {
|
||||||
|
@ -181,37 +181,19 @@ impl Cli {
|
||||||
.help("XXX"),
|
.help("XXX"),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
impl<T: CliOverride> Cli<T> {
|
pub async fn execute(&self, cmd: CliCommand, matches: &clap::ArgMatches) -> anyhow::Result<()> {
|
||||||
pub fn new_with_override(client: Client, over: T) -> Self {
|
|
||||||
Self { client, over }
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn execute(&self, cmd: CliCommand, matches: &clap::ArgMatches) {
|
|
||||||
match cmd {
|
match cmd {
|
||||||
CliCommand::Enrol => {
|
CliCommand::Enrol => self.execute_enrol(matches).await,
|
||||||
self.execute_enrol(matches).await;
|
CliCommand::GlobalJobs => self.execute_global_jobs(matches).await,
|
||||||
}
|
CliCommand::Ping => self.execute_ping(matches).await,
|
||||||
CliCommand::GlobalJobs => {
|
CliCommand::ReportFinish => self.execute_report_finish(matches).await,
|
||||||
self.execute_global_jobs(matches).await;
|
CliCommand::ReportOutput => self.execute_report_output(matches).await,
|
||||||
}
|
CliCommand::ReportStart => self.execute_report_start(matches).await,
|
||||||
CliCommand::Ping => {
|
|
||||||
self.execute_ping(matches).await;
|
|
||||||
}
|
|
||||||
CliCommand::ReportFinish => {
|
|
||||||
self.execute_report_finish(matches).await;
|
|
||||||
}
|
|
||||||
CliCommand::ReportOutput => {
|
|
||||||
self.execute_report_output(matches).await;
|
|
||||||
}
|
|
||||||
CliCommand::ReportStart => {
|
|
||||||
self.execute_report_start(matches).await;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn execute_enrol(&self, matches: &clap::ArgMatches) {
|
pub async fn execute_enrol(&self, matches: &clap::ArgMatches) -> anyhow::Result<()> {
|
||||||
let mut request = self.client.enrol();
|
let mut request = self.client.enrol();
|
||||||
if let Some(value) = matches.get_one::<String>("authorization") {
|
if let Some(value) = matches.get_one::<String>("authorization") {
|
||||||
request = request.authorization(value.clone());
|
request = request.authorization(value.clone());
|
||||||
|
@ -231,57 +213,61 @@ impl<T: CliOverride> Cli<T> {
|
||||||
request = request.body(body_value);
|
request = request.body(body_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.over.execute_enrol(matches, &mut request).unwrap();
|
self.config.execute_enrol(matches, &mut request)?;
|
||||||
let result = request.send().await;
|
let result = request.send().await;
|
||||||
match result {
|
match result {
|
||||||
Ok(r) => {
|
Ok(r) => {
|
||||||
println!("success\n{:#?}", r)
|
self.config.item_success(&r);
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
Err(r) => {
|
Err(r) => {
|
||||||
println!("success\n{:#?}", r)
|
self.config.item_error(&r);
|
||||||
|
Err(anyhow::Error::new(r))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn execute_global_jobs(&self, matches: &clap::ArgMatches) {
|
pub async fn execute_global_jobs(&self, matches: &clap::ArgMatches) -> anyhow::Result<()> {
|
||||||
let mut request = self.client.global_jobs();
|
let mut request = self.client.global_jobs();
|
||||||
if let Some(value) = matches.get_one::<String>("authorization") {
|
if let Some(value) = matches.get_one::<String>("authorization") {
|
||||||
request = request.authorization(value.clone());
|
request = request.authorization(value.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
self.over
|
self.config.execute_global_jobs(matches, &mut request)?;
|
||||||
.execute_global_jobs(matches, &mut request)
|
|
||||||
.unwrap();
|
|
||||||
let result = request.send().await;
|
let result = request.send().await;
|
||||||
match result {
|
match result {
|
||||||
Ok(r) => {
|
Ok(r) => {
|
||||||
println!("success\n{:#?}", r)
|
self.config.item_success(&r);
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
Err(r) => {
|
Err(r) => {
|
||||||
println!("success\n{:#?}", r)
|
self.config.item_error(&r);
|
||||||
|
Err(anyhow::Error::new(r))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn execute_ping(&self, matches: &clap::ArgMatches) {
|
pub async fn execute_ping(&self, matches: &clap::ArgMatches) -> anyhow::Result<()> {
|
||||||
let mut request = self.client.ping();
|
let mut request = self.client.ping();
|
||||||
if let Some(value) = matches.get_one::<String>("authorization") {
|
if let Some(value) = matches.get_one::<String>("authorization") {
|
||||||
request = request.authorization(value.clone());
|
request = request.authorization(value.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
self.over.execute_ping(matches, &mut request).unwrap();
|
self.config.execute_ping(matches, &mut request)?;
|
||||||
let result = request.send().await;
|
let result = request.send().await;
|
||||||
match result {
|
match result {
|
||||||
Ok(r) => {
|
Ok(r) => {
|
||||||
println!("success\n{:#?}", r)
|
self.config.item_success(&r);
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
Err(r) => {
|
Err(r) => {
|
||||||
println!("success\n{:#?}", r)
|
self.config.item_error(&r);
|
||||||
|
Err(anyhow::Error::new(r))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn execute_report_finish(&self, matches: &clap::ArgMatches) {
|
pub async fn execute_report_finish(&self, matches: &clap::ArgMatches) -> anyhow::Result<()> {
|
||||||
let mut request = self.client.report_finish();
|
let mut request = self.client.report_finish();
|
||||||
if let Some(value) = matches.get_one::<String>("authorization") {
|
if let Some(value) = matches.get_one::<String>("authorization") {
|
||||||
request = request.authorization(value.clone());
|
request = request.authorization(value.clone());
|
||||||
|
@ -305,21 +291,21 @@ impl<T: CliOverride> Cli<T> {
|
||||||
request = request.body(body_value);
|
request = request.body(body_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.over
|
self.config.execute_report_finish(matches, &mut request)?;
|
||||||
.execute_report_finish(matches, &mut request)
|
|
||||||
.unwrap();
|
|
||||||
let result = request.send().await;
|
let result = request.send().await;
|
||||||
match result {
|
match result {
|
||||||
Ok(r) => {
|
Ok(r) => {
|
||||||
println!("success\n{:#?}", r)
|
self.config.item_success(&r);
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
Err(r) => {
|
Err(r) => {
|
||||||
println!("success\n{:#?}", r)
|
self.config.item_error(&r);
|
||||||
|
Err(anyhow::Error::new(r))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn execute_report_output(&self, matches: &clap::ArgMatches) {
|
pub async fn execute_report_output(&self, matches: &clap::ArgMatches) -> anyhow::Result<()> {
|
||||||
let mut request = self.client.report_output();
|
let mut request = self.client.report_output();
|
||||||
if let Some(value) = matches.get_one::<String>("authorization") {
|
if let Some(value) = matches.get_one::<String>("authorization") {
|
||||||
request = request.authorization(value.clone());
|
request = request.authorization(value.clone());
|
||||||
|
@ -331,21 +317,21 @@ impl<T: CliOverride> Cli<T> {
|
||||||
request = request.body(body_value);
|
request = request.body(body_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.over
|
self.config.execute_report_output(matches, &mut request)?;
|
||||||
.execute_report_output(matches, &mut request)
|
|
||||||
.unwrap();
|
|
||||||
let result = request.send().await;
|
let result = request.send().await;
|
||||||
match result {
|
match result {
|
||||||
Ok(r) => {
|
Ok(r) => {
|
||||||
println!("success\n{:#?}", r)
|
self.config.item_success(&r);
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
Err(r) => {
|
Err(r) => {
|
||||||
println!("success\n{:#?}", r)
|
self.config.item_error(&r);
|
||||||
|
Err(anyhow::Error::new(r))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn execute_report_start(&self, matches: &clap::ArgMatches) {
|
pub async fn execute_report_start(&self, matches: &clap::ArgMatches) -> anyhow::Result<()> {
|
||||||
let mut request = self.client.report_start();
|
let mut request = self.client.report_start();
|
||||||
if let Some(value) = matches.get_one::<String>("authorization") {
|
if let Some(value) = matches.get_one::<String>("authorization") {
|
||||||
request = request.authorization(value.clone());
|
request = request.authorization(value.clone());
|
||||||
|
@ -366,27 +352,45 @@ impl<T: CliOverride> Cli<T> {
|
||||||
request = request.body(body_value);
|
request = request.body(body_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.over
|
self.config.execute_report_start(matches, &mut request)?;
|
||||||
.execute_report_start(matches, &mut request)
|
|
||||||
.unwrap();
|
|
||||||
let result = request.send().await;
|
let result = request.send().await;
|
||||||
match result {
|
match result {
|
||||||
Ok(r) => {
|
Ok(r) => {
|
||||||
println!("success\n{:#?}", r)
|
self.config.item_success(&r);
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
Err(r) => {
|
Err(r) => {
|
||||||
println!("success\n{:#?}", r)
|
self.config.item_error(&r);
|
||||||
|
Err(anyhow::Error::new(r))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait CliOverride {
|
pub trait CliConfig {
|
||||||
|
fn item_success<T>(&self, value: &ResponseValue<T>)
|
||||||
|
where
|
||||||
|
T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
|
||||||
|
fn item_error<T>(&self, value: &Error<T>)
|
||||||
|
where
|
||||||
|
T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
|
||||||
|
fn list_start<T>(&self)
|
||||||
|
where
|
||||||
|
T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
|
||||||
|
fn list_item<T>(&self, value: &T)
|
||||||
|
where
|
||||||
|
T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
|
||||||
|
fn list_end_success<T>(&self)
|
||||||
|
where
|
||||||
|
T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
|
||||||
|
fn list_end_error<T>(&self, value: &Error<T>)
|
||||||
|
where
|
||||||
|
T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
|
||||||
fn execute_enrol(
|
fn execute_enrol(
|
||||||
&self,
|
&self,
|
||||||
matches: &clap::ArgMatches,
|
matches: &clap::ArgMatches,
|
||||||
request: &mut builder::Enrol,
|
request: &mut builder::Enrol,
|
||||||
) -> Result<(), String> {
|
) -> anyhow::Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -394,7 +398,7 @@ pub trait CliOverride {
|
||||||
&self,
|
&self,
|
||||||
matches: &clap::ArgMatches,
|
matches: &clap::ArgMatches,
|
||||||
request: &mut builder::GlobalJobs,
|
request: &mut builder::GlobalJobs,
|
||||||
) -> Result<(), String> {
|
) -> anyhow::Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -402,7 +406,7 @@ pub trait CliOverride {
|
||||||
&self,
|
&self,
|
||||||
matches: &clap::ArgMatches,
|
matches: &clap::ArgMatches,
|
||||||
request: &mut builder::Ping,
|
request: &mut builder::Ping,
|
||||||
) -> Result<(), String> {
|
) -> anyhow::Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -410,7 +414,7 @@ pub trait CliOverride {
|
||||||
&self,
|
&self,
|
||||||
matches: &clap::ArgMatches,
|
matches: &clap::ArgMatches,
|
||||||
request: &mut builder::ReportFinish,
|
request: &mut builder::ReportFinish,
|
||||||
) -> Result<(), String> {
|
) -> anyhow::Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -418,7 +422,7 @@ pub trait CliOverride {
|
||||||
&self,
|
&self,
|
||||||
matches: &clap::ArgMatches,
|
matches: &clap::ArgMatches,
|
||||||
request: &mut builder::ReportOutput,
|
request: &mut builder::ReportOutput,
|
||||||
) -> Result<(), String> {
|
) -> anyhow::Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -426,12 +430,11 @@ pub trait CliOverride {
|
||||||
&self,
|
&self,
|
||||||
matches: &clap::ArgMatches,
|
matches: &clap::ArgMatches,
|
||||||
request: &mut builder::ReportStart,
|
request: &mut builder::ReportStart,
|
||||||
) -> Result<(), String> {
|
) -> anyhow::Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CliOverride for () {}
|
|
||||||
#[derive(Copy, Clone, Debug)]
|
#[derive(Copy, Clone, Debug)]
|
||||||
pub enum CliCommand {
|
pub enum CliCommand {
|
||||||
Enrol,
|
Enrol,
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,12 +1,12 @@
|
||||||
use crate::param_collision_builder::*;
|
use crate::param_collision_builder::*;
|
||||||
pub struct Cli<T: CliOverride = ()> {
|
pub struct Cli<T: CliConfig> {
|
||||||
client: Client,
|
client: Client,
|
||||||
over: T,
|
config: T,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Cli {
|
impl<T: CliConfig> Cli<T> {
|
||||||
pub fn new(client: Client) -> Self {
|
pub fn new(client: Client, config: T) -> Self {
|
||||||
Self { client, over: () }
|
Self { client, config }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_command(cmd: CliCommand) -> clap::Command {
|
pub fn get_command(cmd: CliCommand) -> clap::Command {
|
||||||
|
@ -61,22 +61,14 @@ impl Cli {
|
||||||
)
|
)
|
||||||
.long_about("Gets a key")
|
.long_about("Gets a key")
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
impl<T: CliOverride> Cli<T> {
|
pub async fn execute(&self, cmd: CliCommand, matches: &clap::ArgMatches) -> anyhow::Result<()> {
|
||||||
pub fn new_with_override(client: Client, over: T) -> Self {
|
|
||||||
Self { client, over }
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn execute(&self, cmd: CliCommand, matches: &clap::ArgMatches) {
|
|
||||||
match cmd {
|
match cmd {
|
||||||
CliCommand::KeyGet => {
|
CliCommand::KeyGet => self.execute_key_get(matches).await,
|
||||||
self.execute_key_get(matches).await;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn execute_key_get(&self, matches: &clap::ArgMatches) {
|
pub async fn execute_key_get(&self, matches: &clap::ArgMatches) -> anyhow::Result<()> {
|
||||||
let mut request = self.client.key_get();
|
let mut request = self.client.key_get();
|
||||||
if let Some(value) = matches.get_one::<bool>("client") {
|
if let Some(value) = matches.get_one::<bool>("client") {
|
||||||
request = request.client(value.clone());
|
request = request.client(value.clone());
|
||||||
|
@ -102,30 +94,49 @@ impl<T: CliOverride> Cli<T> {
|
||||||
request = request.url(value.clone());
|
request = request.url(value.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
self.over.execute_key_get(matches, &mut request).unwrap();
|
self.config.execute_key_get(matches, &mut request)?;
|
||||||
let result = request.send().await;
|
let result = request.send().await;
|
||||||
match result {
|
match result {
|
||||||
Ok(r) => {
|
Ok(r) => {
|
||||||
println!("success\n{:#?}", r)
|
self.config.item_success(&r);
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
Err(r) => {
|
Err(r) => {
|
||||||
println!("success\n{:#?}", r)
|
self.config.item_error(&r);
|
||||||
|
Err(anyhow::Error::new(r))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait CliOverride {
|
pub trait CliConfig {
|
||||||
|
fn item_success<T>(&self, value: &ResponseValue<T>)
|
||||||
|
where
|
||||||
|
T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
|
||||||
|
fn item_error<T>(&self, value: &Error<T>)
|
||||||
|
where
|
||||||
|
T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
|
||||||
|
fn list_start<T>(&self)
|
||||||
|
where
|
||||||
|
T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
|
||||||
|
fn list_item<T>(&self, value: &T)
|
||||||
|
where
|
||||||
|
T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
|
||||||
|
fn list_end_success<T>(&self)
|
||||||
|
where
|
||||||
|
T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
|
||||||
|
fn list_end_error<T>(&self, value: &Error<T>)
|
||||||
|
where
|
||||||
|
T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
|
||||||
fn execute_key_get(
|
fn execute_key_get(
|
||||||
&self,
|
&self,
|
||||||
matches: &clap::ArgMatches,
|
matches: &clap::ArgMatches,
|
||||||
request: &mut builder::KeyGet,
|
request: &mut builder::KeyGet,
|
||||||
) -> Result<(), String> {
|
) -> anyhow::Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CliOverride for () {}
|
|
||||||
#[derive(Copy, Clone, Debug)]
|
#[derive(Copy, Clone, Debug)]
|
||||||
pub enum CliCommand {
|
pub enum CliCommand {
|
||||||
KeyGet,
|
KeyGet,
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
use crate::param_overrides_builder::*;
|
use crate::param_overrides_builder::*;
|
||||||
pub struct Cli<T: CliOverride = ()> {
|
pub struct Cli<T: CliConfig> {
|
||||||
client: Client,
|
client: Client,
|
||||||
over: T,
|
config: T,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Cli {
|
impl<T: CliConfig> Cli<T> {
|
||||||
pub fn new(client: Client) -> Self {
|
pub fn new(client: Client, config: T) -> Self {
|
||||||
Self { client, over: () }
|
Self { client, config }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_command(cmd: CliCommand) -> clap::Command {
|
pub fn get_command(cmd: CliCommand) -> clap::Command {
|
||||||
|
@ -33,22 +33,14 @@ impl Cli {
|
||||||
)
|
)
|
||||||
.long_about("Gets a key")
|
.long_about("Gets a key")
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
impl<T: CliOverride> Cli<T> {
|
pub async fn execute(&self, cmd: CliCommand, matches: &clap::ArgMatches) -> anyhow::Result<()> {
|
||||||
pub fn new_with_override(client: Client, over: T) -> Self {
|
|
||||||
Self { client, over }
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn execute(&self, cmd: CliCommand, matches: &clap::ArgMatches) {
|
|
||||||
match cmd {
|
match cmd {
|
||||||
CliCommand::KeyGet => {
|
CliCommand::KeyGet => self.execute_key_get(matches).await,
|
||||||
self.execute_key_get(matches).await;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn execute_key_get(&self, matches: &clap::ArgMatches) {
|
pub async fn execute_key_get(&self, matches: &clap::ArgMatches) -> anyhow::Result<()> {
|
||||||
let mut request = self.client.key_get();
|
let mut request = self.client.key_get();
|
||||||
if let Some(value) = matches.get_one::<bool>("key") {
|
if let Some(value) = matches.get_one::<bool>("key") {
|
||||||
request = request.key(value.clone());
|
request = request.key(value.clone());
|
||||||
|
@ -58,30 +50,49 @@ impl<T: CliOverride> Cli<T> {
|
||||||
request = request.unique_key(value.clone());
|
request = request.unique_key(value.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
self.over.execute_key_get(matches, &mut request).unwrap();
|
self.config.execute_key_get(matches, &mut request)?;
|
||||||
let result = request.send().await;
|
let result = request.send().await;
|
||||||
match result {
|
match result {
|
||||||
Ok(r) => {
|
Ok(r) => {
|
||||||
println!("success\n{:#?}", r)
|
self.config.item_success(&r);
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
Err(r) => {
|
Err(r) => {
|
||||||
println!("success\n{:#?}", r)
|
self.config.item_error(&r);
|
||||||
|
Err(anyhow::Error::new(r))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait CliOverride {
|
pub trait CliConfig {
|
||||||
|
fn item_success<T>(&self, value: &ResponseValue<T>)
|
||||||
|
where
|
||||||
|
T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
|
||||||
|
fn item_error<T>(&self, value: &Error<T>)
|
||||||
|
where
|
||||||
|
T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
|
||||||
|
fn list_start<T>(&self)
|
||||||
|
where
|
||||||
|
T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
|
||||||
|
fn list_item<T>(&self, value: &T)
|
||||||
|
where
|
||||||
|
T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
|
||||||
|
fn list_end_success<T>(&self)
|
||||||
|
where
|
||||||
|
T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
|
||||||
|
fn list_end_error<T>(&self, value: &Error<T>)
|
||||||
|
where
|
||||||
|
T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
|
||||||
fn execute_key_get(
|
fn execute_key_get(
|
||||||
&self,
|
&self,
|
||||||
matches: &clap::ArgMatches,
|
matches: &clap::ArgMatches,
|
||||||
request: &mut builder::KeyGet,
|
request: &mut builder::KeyGet,
|
||||||
) -> Result<(), String> {
|
) -> anyhow::Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CliOverride for () {}
|
|
||||||
#[derive(Copy, Clone, Debug)]
|
#[derive(Copy, Clone, Debug)]
|
||||||
pub enum CliCommand {
|
pub enum CliCommand {
|
||||||
KeyGet,
|
KeyGet,
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
use crate::propolis_server_builder::*;
|
use crate::propolis_server_builder::*;
|
||||||
pub struct Cli<T: CliOverride = ()> {
|
pub struct Cli<T: CliConfig> {
|
||||||
client: Client,
|
client: Client,
|
||||||
over: T,
|
config: T,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Cli {
|
impl<T: CliConfig> Cli<T> {
|
||||||
pub fn new(client: Client) -> Self {
|
pub fn new(client: Client, config: T) -> Self {
|
||||||
Self { client, over: () }
|
Self { client, config }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_command(cmd: CliCommand) -> clap::Command {
|
pub fn get_command(cmd: CliCommand) -> clap::Command {
|
||||||
|
@ -137,57 +137,41 @@ impl Cli {
|
||||||
.help("XXX"),
|
.help("XXX"),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
impl<T: CliOverride> Cli<T> {
|
pub async fn execute(&self, cmd: CliCommand, matches: &clap::ArgMatches) -> anyhow::Result<()> {
|
||||||
pub fn new_with_override(client: Client, over: T) -> Self {
|
|
||||||
Self { client, over }
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn execute(&self, cmd: CliCommand, matches: &clap::ArgMatches) {
|
|
||||||
match cmd {
|
match cmd {
|
||||||
CliCommand::InstanceGet => {
|
CliCommand::InstanceGet => self.execute_instance_get(matches).await,
|
||||||
self.execute_instance_get(matches).await;
|
CliCommand::InstanceEnsure => self.execute_instance_ensure(matches).await,
|
||||||
}
|
|
||||||
CliCommand::InstanceEnsure => {
|
|
||||||
self.execute_instance_ensure(matches).await;
|
|
||||||
}
|
|
||||||
CliCommand::InstanceIssueCrucibleSnapshotRequest => {
|
CliCommand::InstanceIssueCrucibleSnapshotRequest => {
|
||||||
self.execute_instance_issue_crucible_snapshot_request(matches)
|
self.execute_instance_issue_crucible_snapshot_request(matches)
|
||||||
.await;
|
.await
|
||||||
}
|
}
|
||||||
CliCommand::InstanceMigrateStatus => {
|
CliCommand::InstanceMigrateStatus => {
|
||||||
self.execute_instance_migrate_status(matches).await;
|
self.execute_instance_migrate_status(matches).await
|
||||||
}
|
|
||||||
CliCommand::InstanceSerial => {
|
|
||||||
self.execute_instance_serial(matches).await;
|
|
||||||
}
|
|
||||||
CliCommand::InstanceStatePut => {
|
|
||||||
self.execute_instance_state_put(matches).await;
|
|
||||||
}
|
|
||||||
CliCommand::InstanceStateMonitor => {
|
|
||||||
self.execute_instance_state_monitor(matches).await;
|
|
||||||
}
|
}
|
||||||
|
CliCommand::InstanceSerial => self.execute_instance_serial(matches).await,
|
||||||
|
CliCommand::InstanceStatePut => self.execute_instance_state_put(matches).await,
|
||||||
|
CliCommand::InstanceStateMonitor => self.execute_instance_state_monitor(matches).await,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn execute_instance_get(&self, matches: &clap::ArgMatches) {
|
pub async fn execute_instance_get(&self, matches: &clap::ArgMatches) -> anyhow::Result<()> {
|
||||||
let mut request = self.client.instance_get();
|
let mut request = self.client.instance_get();
|
||||||
self.over
|
self.config.execute_instance_get(matches, &mut request)?;
|
||||||
.execute_instance_get(matches, &mut request)
|
|
||||||
.unwrap();
|
|
||||||
let result = request.send().await;
|
let result = request.send().await;
|
||||||
match result {
|
match result {
|
||||||
Ok(r) => {
|
Ok(r) => {
|
||||||
println!("success\n{:#?}", r)
|
self.config.item_success(&r);
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
Err(r) => {
|
Err(r) => {
|
||||||
println!("error\n{:#?}", r)
|
self.config.item_error(&r);
|
||||||
|
Err(anyhow::Error::new(r))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn execute_instance_ensure(&self, matches: &clap::ArgMatches) {
|
pub async fn execute_instance_ensure(&self, matches: &clap::ArgMatches) -> anyhow::Result<()> {
|
||||||
let mut request = self.client.instance_ensure();
|
let mut request = self.client.instance_ensure();
|
||||||
if let Some(value) = matches.get_one::<String>("cloud-init-bytes") {
|
if let Some(value) = matches.get_one::<String>("cloud-init-bytes") {
|
||||||
request = request.body_map(|body| body.cloud_init_bytes(value.clone()))
|
request = request.body_map(|body| body.cloud_init_bytes(value.clone()))
|
||||||
|
@ -200,16 +184,16 @@ impl<T: CliOverride> Cli<T> {
|
||||||
request = request.body(body_value);
|
request = request.body(body_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.over
|
self.config.execute_instance_ensure(matches, &mut request)?;
|
||||||
.execute_instance_ensure(matches, &mut request)
|
|
||||||
.unwrap();
|
|
||||||
let result = request.send().await;
|
let result = request.send().await;
|
||||||
match result {
|
match result {
|
||||||
Ok(r) => {
|
Ok(r) => {
|
||||||
println!("success\n{:#?}", r)
|
self.config.item_success(&r);
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
Err(r) => {
|
Err(r) => {
|
||||||
println!("error\n{:#?}", r)
|
self.config.item_error(&r);
|
||||||
|
Err(anyhow::Error::new(r))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -217,7 +201,7 @@ impl<T: CliOverride> Cli<T> {
|
||||||
pub async fn execute_instance_issue_crucible_snapshot_request(
|
pub async fn execute_instance_issue_crucible_snapshot_request(
|
||||||
&self,
|
&self,
|
||||||
matches: &clap::ArgMatches,
|
matches: &clap::ArgMatches,
|
||||||
) {
|
) -> anyhow::Result<()> {
|
||||||
let mut request = self.client.instance_issue_crucible_snapshot_request();
|
let mut request = self.client.instance_issue_crucible_snapshot_request();
|
||||||
if let Some(value) = matches.get_one::<uuid::Uuid>("id") {
|
if let Some(value) = matches.get_one::<uuid::Uuid>("id") {
|
||||||
request = request.id(value.clone());
|
request = request.id(value.clone());
|
||||||
|
@ -227,21 +211,25 @@ impl<T: CliOverride> Cli<T> {
|
||||||
request = request.snapshot_id(value.clone());
|
request = request.snapshot_id(value.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
self.over
|
self.config
|
||||||
.execute_instance_issue_crucible_snapshot_request(matches, &mut request)
|
.execute_instance_issue_crucible_snapshot_request(matches, &mut request)?;
|
||||||
.unwrap();
|
|
||||||
let result = request.send().await;
|
let result = request.send().await;
|
||||||
match result {
|
match result {
|
||||||
Ok(r) => {
|
Ok(r) => {
|
||||||
println!("success\n{:#?}", r)
|
self.config.item_success(&r);
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
Err(r) => {
|
Err(r) => {
|
||||||
println!("error\n{:#?}", r)
|
self.config.item_error(&r);
|
||||||
|
Err(anyhow::Error::new(r))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn execute_instance_migrate_status(&self, matches: &clap::ArgMatches) {
|
pub async fn execute_instance_migrate_status(
|
||||||
|
&self,
|
||||||
|
matches: &clap::ArgMatches,
|
||||||
|
) -> anyhow::Result<()> {
|
||||||
let mut request = self.client.instance_migrate_status();
|
let mut request = self.client.instance_migrate_status();
|
||||||
if let Some(value) = matches.get_one::<uuid::Uuid>("migration-id") {
|
if let Some(value) = matches.get_one::<uuid::Uuid>("migration-id") {
|
||||||
request = request.body_map(|body| body.migration_id(value.clone()))
|
request = request.body_map(|body| body.migration_id(value.clone()))
|
||||||
|
@ -254,25 +242,24 @@ impl<T: CliOverride> Cli<T> {
|
||||||
request = request.body(body_value);
|
request = request.body(body_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.over
|
self.config
|
||||||
.execute_instance_migrate_status(matches, &mut request)
|
.execute_instance_migrate_status(matches, &mut request)?;
|
||||||
.unwrap();
|
|
||||||
let result = request.send().await;
|
let result = request.send().await;
|
||||||
match result {
|
match result {
|
||||||
Ok(r) => {
|
Ok(r) => {
|
||||||
println!("success\n{:#?}", r)
|
self.config.item_success(&r);
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
Err(r) => {
|
Err(r) => {
|
||||||
println!("error\n{:#?}", r)
|
self.config.item_error(&r);
|
||||||
|
Err(anyhow::Error::new(r))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn execute_instance_serial(&self, matches: &clap::ArgMatches) {
|
pub async fn execute_instance_serial(&self, matches: &clap::ArgMatches) -> anyhow::Result<()> {
|
||||||
let mut request = self.client.instance_serial();
|
let mut request = self.client.instance_serial();
|
||||||
self.over
|
self.config.execute_instance_serial(matches, &mut request)?;
|
||||||
.execute_instance_serial(matches, &mut request)
|
|
||||||
.unwrap();
|
|
||||||
let result = request.send().await;
|
let result = request.send().await;
|
||||||
match result {
|
match result {
|
||||||
Ok(r) => {
|
Ok(r) => {
|
||||||
|
@ -284,7 +271,10 @@ impl<T: CliOverride> Cli<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn execute_instance_state_put(&self, matches: &clap::ArgMatches) {
|
pub async fn execute_instance_state_put(
|
||||||
|
&self,
|
||||||
|
matches: &clap::ArgMatches,
|
||||||
|
) -> anyhow::Result<()> {
|
||||||
let mut request = self.client.instance_state_put();
|
let mut request = self.client.instance_state_put();
|
||||||
if let Some(value) = matches.get_one::<std::path::PathBuf>("json-body") {
|
if let Some(value) = matches.get_one::<std::path::PathBuf>("json-body") {
|
||||||
let body_txt = std::fs::read_to_string(value).unwrap();
|
let body_txt = std::fs::read_to_string(value).unwrap();
|
||||||
|
@ -293,21 +283,25 @@ impl<T: CliOverride> Cli<T> {
|
||||||
request = request.body(body_value);
|
request = request.body(body_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.over
|
self.config
|
||||||
.execute_instance_state_put(matches, &mut request)
|
.execute_instance_state_put(matches, &mut request)?;
|
||||||
.unwrap();
|
|
||||||
let result = request.send().await;
|
let result = request.send().await;
|
||||||
match result {
|
match result {
|
||||||
Ok(r) => {
|
Ok(r) => {
|
||||||
println!("success\n{:#?}", r)
|
self.config.item_success(&r);
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
Err(r) => {
|
Err(r) => {
|
||||||
println!("error\n{:#?}", r)
|
self.config.item_error(&r);
|
||||||
|
Err(anyhow::Error::new(r))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn execute_instance_state_monitor(&self, matches: &clap::ArgMatches) {
|
pub async fn execute_instance_state_monitor(
|
||||||
|
&self,
|
||||||
|
matches: &clap::ArgMatches,
|
||||||
|
) -> anyhow::Result<()> {
|
||||||
let mut request = self.client.instance_state_monitor();
|
let mut request = self.client.instance_state_monitor();
|
||||||
if let Some(value) = matches.get_one::<u64>("gen") {
|
if let Some(value) = matches.get_one::<u64>("gen") {
|
||||||
request = request.body_map(|body| body.gen(value.clone()))
|
request = request.body_map(|body| body.gen(value.clone()))
|
||||||
|
@ -320,27 +314,46 @@ impl<T: CliOverride> Cli<T> {
|
||||||
request = request.body(body_value);
|
request = request.body(body_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.over
|
self.config
|
||||||
.execute_instance_state_monitor(matches, &mut request)
|
.execute_instance_state_monitor(matches, &mut request)?;
|
||||||
.unwrap();
|
|
||||||
let result = request.send().await;
|
let result = request.send().await;
|
||||||
match result {
|
match result {
|
||||||
Ok(r) => {
|
Ok(r) => {
|
||||||
println!("success\n{:#?}", r)
|
self.config.item_success(&r);
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
Err(r) => {
|
Err(r) => {
|
||||||
println!("error\n{:#?}", r)
|
self.config.item_error(&r);
|
||||||
|
Err(anyhow::Error::new(r))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait CliOverride {
|
pub trait CliConfig {
|
||||||
|
fn item_success<T>(&self, value: &ResponseValue<T>)
|
||||||
|
where
|
||||||
|
T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
|
||||||
|
fn item_error<T>(&self, value: &Error<T>)
|
||||||
|
where
|
||||||
|
T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
|
||||||
|
fn list_start<T>(&self)
|
||||||
|
where
|
||||||
|
T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
|
||||||
|
fn list_item<T>(&self, value: &T)
|
||||||
|
where
|
||||||
|
T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
|
||||||
|
fn list_end_success<T>(&self)
|
||||||
|
where
|
||||||
|
T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
|
||||||
|
fn list_end_error<T>(&self, value: &Error<T>)
|
||||||
|
where
|
||||||
|
T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
|
||||||
fn execute_instance_get(
|
fn execute_instance_get(
|
||||||
&self,
|
&self,
|
||||||
matches: &clap::ArgMatches,
|
matches: &clap::ArgMatches,
|
||||||
request: &mut builder::InstanceGet,
|
request: &mut builder::InstanceGet,
|
||||||
) -> Result<(), String> {
|
) -> anyhow::Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -348,7 +361,7 @@ pub trait CliOverride {
|
||||||
&self,
|
&self,
|
||||||
matches: &clap::ArgMatches,
|
matches: &clap::ArgMatches,
|
||||||
request: &mut builder::InstanceEnsure,
|
request: &mut builder::InstanceEnsure,
|
||||||
) -> Result<(), String> {
|
) -> anyhow::Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -356,7 +369,7 @@ pub trait CliOverride {
|
||||||
&self,
|
&self,
|
||||||
matches: &clap::ArgMatches,
|
matches: &clap::ArgMatches,
|
||||||
request: &mut builder::InstanceIssueCrucibleSnapshotRequest,
|
request: &mut builder::InstanceIssueCrucibleSnapshotRequest,
|
||||||
) -> Result<(), String> {
|
) -> anyhow::Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -364,7 +377,7 @@ pub trait CliOverride {
|
||||||
&self,
|
&self,
|
||||||
matches: &clap::ArgMatches,
|
matches: &clap::ArgMatches,
|
||||||
request: &mut builder::InstanceMigrateStatus,
|
request: &mut builder::InstanceMigrateStatus,
|
||||||
) -> Result<(), String> {
|
) -> anyhow::Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -372,7 +385,7 @@ pub trait CliOverride {
|
||||||
&self,
|
&self,
|
||||||
matches: &clap::ArgMatches,
|
matches: &clap::ArgMatches,
|
||||||
request: &mut builder::InstanceSerial,
|
request: &mut builder::InstanceSerial,
|
||||||
) -> Result<(), String> {
|
) -> anyhow::Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -380,7 +393,7 @@ pub trait CliOverride {
|
||||||
&self,
|
&self,
|
||||||
matches: &clap::ArgMatches,
|
matches: &clap::ArgMatches,
|
||||||
request: &mut builder::InstanceStatePut,
|
request: &mut builder::InstanceStatePut,
|
||||||
) -> Result<(), String> {
|
) -> anyhow::Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -388,12 +401,11 @@ pub trait CliOverride {
|
||||||
&self,
|
&self,
|
||||||
matches: &clap::ArgMatches,
|
matches: &clap::ArgMatches,
|
||||||
request: &mut builder::InstanceStateMonitor,
|
request: &mut builder::InstanceStateMonitor,
|
||||||
) -> Result<(), String> {
|
) -> anyhow::Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CliOverride for () {}
|
|
||||||
#[derive(Copy, Clone, Debug)]
|
#[derive(Copy, Clone, Debug)]
|
||||||
pub enum CliCommand {
|
pub enum CliCommand {
|
||||||
InstanceGet,
|
InstanceGet,
|
||||||
|
|
Loading…
Reference in New Issue