Skip to content

Commit

Permalink
Build generated clients
Browse files Browse the repository at this point in the history
  • Loading branch information
jayvdb committed Dec 3, 2023
1 parent 8d1b8f0 commit 246e0f6
Show file tree
Hide file tree
Showing 41 changed files with 3,748 additions and 605 deletions.
38 changes: 30 additions & 8 deletions progenitor-impl/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl Generator {

let methods = raw_methods
.iter()
.map(|method| self.cli_method(method))
.map(|method| self.cli_method(method, crate_name))
.collect::<Vec<_>>();

let cli_ops = methods.iter().map(|op| &op.cli_fn);
Expand Down Expand Up @@ -100,15 +100,25 @@ impl Generator {
})
.collect::<Vec<_>>();

let crate_ident = format_ident!("{}", crate_name);
let crate_path = syn::TypePath {
qself: None,
path: syn::parse_str(&format!("{}", crate_name)).unwrap(),
};

let client_path = syn::TypePath {
qself: None,
path: syn::parse_str(&format!("{}::Client", crate_name)).unwrap(),
};

let code = quote! {
use #crate_path :: *;

pub struct Cli<T: CliOverride = ()> {
client: #crate_ident::Client,
client: #client_path,
over: T,
}
impl Cli {
pub fn new(client: #crate_ident::Client) -> Self {
pub fn new(client: #client_path) -> Self {
Self { client, over: () }
}

Expand All @@ -125,7 +135,7 @@ impl Generator {

impl<T: CliOverride> Cli<T> {
pub fn new_with_override(
client: #crate_ident::Client,
client: #client_path,
over: T,
) -> Self {
Self { client, over }
Expand Down Expand Up @@ -178,11 +188,17 @@ impl Generator {
fn cli_method(
&mut self,
method: &crate::method::OperationMethod,
crate_name: &str,
) -> CliOperation {
let CliArg {
parser: parser_args,
consumer: consumer_args,
} = self.cli_method_args(method);
} = self.cli_method_args(method, crate_name);

let crate_builder_path = syn::TypePath {
qself: None,
path: syn::parse_str(&format!("{}::builder", crate_name)).unwrap(),
};

let about = method.summary.as_ref().map(|summary| {
quote! {
Expand Down Expand Up @@ -305,7 +321,7 @@ impl Generator {
fn #fn_name(
&self,
matches: &clap::ArgMatches,
request: &mut builder :: #struct_ident,
request: &mut #crate_builder_path :: #struct_ident,
) -> Result<(), String> {
Ok(())
}
Expand All @@ -321,9 +337,15 @@ impl Generator {
fn cli_method_args(
&self,
method: &crate::method::OperationMethod,
crate_name: &str,
) -> CliArg {
let mut args = CliOperationArgs::default();

let crate_path = syn::TypePath {
qself: None,
path: syn::parse_str(&format!("{}", crate_name)).unwrap(),
};

let first_page_required_set = method
.dropshot_paginated
.as_ref()
Expand Down Expand Up @@ -481,7 +503,7 @@ impl Generator {
{
let body_txt = std::fs::read_to_string(value).unwrap();
let body_value =
serde_json::from_str::<#body_type_ident>(
serde_json::from_str::<#crate_path :: #body_type_ident>(
&body_txt,
)
.unwrap();
Expand Down
7 changes: 5 additions & 2 deletions progenitor-impl/src/httpmock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ impl Generator {
let then_impl =
methods.iter().map(|op| &op.then_impl).collect::<Vec<_>>();

let crate_ident = format_ident!("{}", crate_name);
let crate_path = syn::TypePath {
qself: None,
path: syn::parse_str(&format!("{}", crate_name)).unwrap(),
};

let code = quote! {
pub mod operations {
Expand All @@ -89,7 +92,7 @@ impl Generator {
//! its inner type with a call to `into_inner()`. This can
//! be used to explicitly deviate from permitted values.
use #crate_ident::*;
use #crate_path::*;

#(
pub struct #when(httpmock::When);
Expand Down
Loading

0 comments on commit 246e0f6

Please sign in to comment.