Skip to content

Commit

Permalink
Allow API to reside at submodule of crate
Browse files Browse the repository at this point in the history
  • Loading branch information
jayvdb committed Dec 13, 2023
1 parent afa2e7e commit be990a6
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 24 deletions.
13 changes: 9 additions & 4 deletions progenitor-impl/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,20 @@ impl Generator {
})
.collect::<Vec<_>>();

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

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

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

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

impl<T: CliOverride> Cli<T> {
pub fn new_with_override(
client: #crate_ident::Client,
client: Client,
over: T,
) -> Self {
Self { client, over }
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(&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
7 changes: 4 additions & 3 deletions progenitor-impl/tests/output/buildomat-cli.out
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use sdk::*;
pub struct Cli<T: CliOverride = ()> {
client: sdk::Client,
client: Client,
over: T,
}

impl Cli {
pub fn new(client: sdk::Client) -> Self {
pub fn new(client: Client) -> Self {
Self { client, over: () }
}

Expand Down Expand Up @@ -317,7 +318,7 @@ impl Cli {
}

impl<T: CliOverride> Cli<T> {
pub fn new_with_override(client: sdk::Client, over: T) -> Self {
pub fn new_with_override(client: Client, over: T) -> Self {
Self { client, over }
}

Expand Down
7 changes: 4 additions & 3 deletions progenitor-impl/tests/output/keeper-cli.out
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use sdk::*;
pub struct Cli<T: CliOverride = ()> {
client: sdk::Client,
client: Client,
over: T,
}

impl Cli {
pub fn new(client: sdk::Client) -> Self {
pub fn new(client: Client) -> Self {
Self { client, over: () }
}

Expand Down Expand Up @@ -183,7 +184,7 @@ impl Cli {
}

impl<T: CliOverride> Cli<T> {
pub fn new_with_override(client: sdk::Client, over: T) -> Self {
pub fn new_with_override(client: Client, over: T) -> Self {
Self { client, over }
}

Expand Down
7 changes: 4 additions & 3 deletions progenitor-impl/tests/output/nexus-cli.out
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use sdk::*;
pub struct Cli<T: CliOverride = ()> {
client: sdk::Client,
client: Client,
over: T,
}

impl Cli {
pub fn new(client: sdk::Client) -> Self {
pub fn new(client: Client) -> Self {
Self { client, over: () }
}

Expand Down Expand Up @@ -5608,7 +5609,7 @@ impl Cli {
}

impl<T: CliOverride> Cli<T> {
pub fn new_with_override(client: sdk::Client, over: T) -> Self {
pub fn new_with_override(client: Client, over: T) -> Self {
Self { client, over }
}

Expand Down
7 changes: 4 additions & 3 deletions progenitor-impl/tests/output/param-collision-cli.out
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use sdk::*;
pub struct Cli<T: CliOverride = ()> {
client: sdk::Client,
client: Client,
over: T,
}

impl Cli {
pub fn new(client: sdk::Client) -> Self {
pub fn new(client: Client) -> Self {
Self { client, over: () }
}

Expand Down Expand Up @@ -63,7 +64,7 @@ impl Cli {
}

impl<T: CliOverride> Cli<T> {
pub fn new_with_override(client: sdk::Client, over: T) -> Self {
pub fn new_with_override(client: Client, over: T) -> Self {
Self { client, over }
}

Expand Down
7 changes: 4 additions & 3 deletions progenitor-impl/tests/output/param-overrides-cli.out
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use sdk::*;
pub struct Cli<T: CliOverride = ()> {
client: sdk::Client,
client: Client,
over: T,
}

impl Cli {
pub fn new(client: sdk::Client) -> Self {
pub fn new(client: Client) -> Self {
Self { client, over: () }
}

Expand Down Expand Up @@ -35,7 +36,7 @@ impl Cli {
}

impl<T: CliOverride> Cli<T> {
pub fn new_with_override(client: sdk::Client, over: T) -> Self {
pub fn new_with_override(client: Client, over: T) -> Self {
Self { client, over }
}

Expand Down
7 changes: 4 additions & 3 deletions progenitor-impl/tests/output/propolis-server-cli.out
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use sdk::*;
pub struct Cli<T: CliOverride = ()> {
client: sdk::Client,
client: Client,
over: T,
}

impl Cli {
pub fn new(client: sdk::Client) -> Self {
pub fn new(client: Client) -> Self {
Self { client, over: () }
}

Expand Down Expand Up @@ -139,7 +140,7 @@ impl Cli {
}

impl<T: CliOverride> Cli<T> {
pub fn new_with_override(client: sdk::Client, over: T) -> Self {
pub fn new_with_override(client: Client, over: T) -> Self {
Self { client, over }
}

Expand Down

0 comments on commit be990a6

Please sign in to comment.