Skip to content

Commit 09489b3

Browse files
ahlabus-sh
authored andcommitted
fully qualify generated uses of httpmock and clap (oxidecomputer#993)
1 parent 8dab04f commit 09489b3

16 files changed

+4619
-4495
lines changed

progenitor-impl/src/cli.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ impl Generator {
120120
Self { client, config }
121121
}
122122

123-
pub fn get_command(cmd: CliCommand) -> clap::Command {
123+
pub fn get_command(cmd: CliCommand) -> ::clap::Command {
124124
match cmd {
125125
#(
126126
CliCommand::#cli_variants => Self::#cli_fns(),
@@ -133,7 +133,7 @@ impl Generator {
133133
pub async fn execute(
134134
&self,
135135
cmd: CliCommand,
136-
matches: &clap::ArgMatches,
136+
matches: &::clap::ArgMatches,
137137
) -> anyhow::Result<()> {
138138
match cmd {
139139
#(
@@ -217,9 +217,9 @@ impl Generator {
217217
let fn_name = format_ident!("cli_{}", &method.operation_id);
218218

219219
let cli_fn = quote! {
220-
pub fn #fn_name() -> clap::Command
220+
pub fn #fn_name() -> ::clap::Command
221221
{
222-
clap::Command::new("")
222+
::clap::Command::new("")
223223
#parser_args
224224
#about
225225
#long_about
@@ -361,7 +361,7 @@ impl Generator {
361361
};
362362

363363
let execute_fn = quote! {
364-
pub async fn #fn_name(&self, matches: &clap::ArgMatches)
364+
pub async fn #fn_name(&self, matches: &::clap::ArgMatches)
365365
-> anyhow::Result<()>
366366
{
367367
let mut request = self.client.#op_name();
@@ -381,7 +381,7 @@ impl Generator {
381381
let execute_trait = quote! {
382382
fn #fn_name(
383383
&self,
384-
matches: &clap::ArgMatches,
384+
matches: &::clap::ArgMatches,
385385
request: &mut builder :: #struct_ident,
386386
) -> anyhow::Result<()> {
387387
Ok(())
@@ -521,19 +521,19 @@ impl Generator {
521521

522522
quote! {
523523
.arg(
524-
clap::Arg::new("json-body")
524+
::clap::Arg::new("json-body")
525525
.long("json-body")
526526
.value_name("JSON-FILE")
527527
// Required if we can't turn the body into individual
528528
// parameters.
529529
.required(#required)
530-
.value_parser(clap::value_parser!(std::path::PathBuf))
530+
.value_parser(::clap::value_parser!(std::path::PathBuf))
531531
.help(#help)
532532
)
533533
.arg(
534-
clap::Arg::new("json-body-template")
534+
::clap::Arg::new("json-body-template")
535535
.long("json-body-template")
536-
.action(clap::ArgAction::SetTrue)
536+
.action(::clap::ArgAction::SetTrue)
537537
.help("XXX")
538538
)
539539
}
@@ -704,8 +704,8 @@ fn clap_arg(
704704

705705
maybe_var_names.map(|var_names| {
706706
quote! {
707-
clap::builder::TypedValueParser::map(
708-
clap::builder::PossibleValuesParser::new([
707+
::clap::builder::TypedValueParser::map(
708+
::clap::builder::PossibleValuesParser::new([
709709
#( #arg_type_name :: #var_names.to_string(), )*
710710
]),
711711
|s| #arg_type_name :: try_from(s).unwrap()
@@ -723,7 +723,7 @@ fn clap_arg(
723723
// allowing for override implementations. A generated client may
724724
// implement ValueParserFactory for a type to create a custom parser.
725725
quote! {
726-
clap::value_parser!(#arg_type_name)
726+
::clap::value_parser!(#arg_type_name)
727727
}
728728
};
729729

@@ -736,7 +736,7 @@ fn clap_arg(
736736
};
737737

738738
quote! {
739-
clap::Arg::new(#arg_name)
739+
::clap::Arg::new(#arg_name)
740740
.long(#arg_name)
741741
.value_parser(#value_parser)
742742
#required

progenitor-impl/src/httpmock.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2023 Oxide Computer Company
1+
// Copyright 2024 Oxide Computer Company
22

33
//! Generation of mocking extensions for `httpmock`
44
@@ -94,36 +94,36 @@ impl Generator {
9494
let code = quote! {
9595
pub mod operations {
9696

97-
//! [`When`](httpmock::When) and [`Then`](httpmock::Then)
97+
//! [`When`](::httpmock::When) and [`Then`](::httpmock::Then)
9898
//! wrappers for each operation. Each can be converted to
9999
//! its inner type with a call to `into_inner()`. This can
100100
//! be used to explicitly deviate from permitted values.
101101
102102
use #crate_path::*;
103103

104104
#(
105-
pub struct #when(httpmock::When);
105+
pub struct #when(::httpmock::When);
106106
#when_impl
107107

108-
pub struct #then(httpmock::Then);
108+
pub struct #then(::httpmock::Then);
109109
#then_impl
110110
)*
111111
}
112112

113-
/// An extension trait for [`MockServer`](httpmock::MockServer) that
113+
/// An extension trait for [`MockServer`](::httpmock::MockServer) that
114114
/// adds a method for each operation. These are the equivalent of
115-
/// type-checked [`mock()`](httpmock::MockServer::mock) calls.
115+
/// type-checked [`mock()`](::httpmock::MockServer::mock) calls.
116116
pub trait MockServerExt {
117117
#(
118-
fn #op<F>(&self, config_fn: F) -> httpmock::Mock
118+
fn #op<F>(&self, config_fn: F) -> ::httpmock::Mock
119119
where
120120
F: FnOnce(operations::#when, operations::#then);
121121
)*
122122
}
123123

124-
impl MockServerExt for httpmock::MockServer {
124+
impl MockServerExt for ::httpmock::MockServer {
125125
#(
126-
fn #op<F>(&self, config_fn: F) -> httpmock::Mock
126+
fn #op<F>(&self, config_fn: F) -> ::httpmock::Mock
127127
where
128128
F: FnOnce(operations::#when, operations::#then)
129129
{
@@ -152,14 +152,14 @@ impl Generator {
152152
let then = format_ident!("{}", then_name).to_token_stream();
153153

154154
let http_method = match &method.method {
155-
HttpMethod::Get => quote! { httpmock::Method::GET },
156-
HttpMethod::Put => quote! { httpmock::Method::PUT },
157-
HttpMethod::Post => quote! { httpmock::Method::POST },
158-
HttpMethod::Delete => quote! { httpmock::Method::DELETE },
159-
HttpMethod::Options => quote! { httpmock::Method::OPTIONS },
160-
HttpMethod::Head => quote! { httpmock::Method::HEAD },
161-
HttpMethod::Patch => quote! { httpmock::Method::PATCH },
162-
HttpMethod::Trace => quote! { httpmock::Method::TRACE },
155+
HttpMethod::Get => quote! { ::httpmock::Method::GET },
156+
HttpMethod::Put => quote! { ::httpmock::Method::PUT },
157+
HttpMethod::Post => quote! { ::httpmock::Method::POST },
158+
HttpMethod::Delete => quote! { ::httpmock::Method::DELETE },
159+
HttpMethod::Options => quote! { ::httpmock::Method::OPTIONS },
160+
HttpMethod::Head => quote! { ::httpmock::Method::HEAD },
161+
HttpMethod::Patch => quote! { ::httpmock::Method::PATCH },
162+
HttpMethod::Trace => quote! { ::httpmock::Method::TRACE },
163163
};
164164

165165
let path_re = method.path.as_wildcard();
@@ -284,13 +284,13 @@ impl Generator {
284284

285285
let when_impl = quote! {
286286
impl #when {
287-
pub fn new(inner: httpmock::When) -> Self {
287+
pub fn new(inner: ::httpmock::When) -> Self {
288288
Self(inner
289289
.method(#http_method)
290290
.path_matches(regex::Regex::new(#path_re).unwrap()))
291291
}
292292

293-
pub fn into_inner(self) -> httpmock::When {
293+
pub fn into_inner(self) -> ::httpmock::When {
294294
self.0
295295
}
296296

@@ -404,11 +404,11 @@ impl Generator {
404404

405405
let then_impl = quote! {
406406
impl #then {
407-
pub fn new(inner: httpmock::Then) -> Self {
407+
pub fn new(inner: ::httpmock::Then) -> Self {
408408
Self(inner)
409409
}
410410

411-
pub fn into_inner(self) -> httpmock::Then {
411+
pub fn into_inner(self) -> ::httpmock::Then {
412412
self.0
413413
}
414414

0 commit comments

Comments
 (0)