Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions progenitor-impl/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::collections::BTreeMap;
use heck::ToKebabCase;
use openapiv3::OpenAPI;
use proc_macro2::TokenStream;
use quote::{format_ident, quote};
use quote::{format_ident, quote, ToTokens};
use typify::{Type, TypeEnumVariant, TypeSpaceImpl, TypeStructPropInfo};

use crate::{
Expand Down Expand Up @@ -79,6 +79,13 @@ impl Generator {
path: syn::parse_str(crate_name).unwrap(),
};

let cli_bounds: Vec<_> = self
.settings
.extra_cli_bounds
.iter()
.map(|b| syn::parse_str::<syn::Path>(b).unwrap().into_token_stream())
.collect();

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

Expand Down Expand Up @@ -125,24 +132,24 @@ impl Generator {
pub trait CliConfig {
fn success_item<T>(&self, value: &ResponseValue<T>)
where
T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
T: #(#cli_bounds+)* schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
fn success_no_item(&self, value: &ResponseValue<()>);
fn error<T>(&self, value: &Error<T>)
where
T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
T: #(#cli_bounds+)* schemars::JsonSchema + serde::Serialize + std::fmt::Debug;

fn list_start<T>(&self)
where
T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
T: #(#cli_bounds+)* schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
fn list_item<T>(&self, value: &T)
where
T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
T: #(#cli_bounds+)* schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
fn list_end_success<T>(&self)
where
T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
T: #(#cli_bounds+)* 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;
T: #(#cli_bounds+)* schemars::JsonSchema + serde::Serialize + std::fmt::Debug;

#(#trait_ops)*
}
Expand Down
7 changes: 7 additions & 0 deletions progenitor-impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ pub struct GenerationSettings {
post_hook: Option<TokenStream>,
post_hook_async: Option<TokenStream>,
extra_derives: Vec<String>,
extra_cli_bounds: Vec<String>,

map_type: Option<String>,
unknown_crates: UnknownPolicy,
Expand Down Expand Up @@ -166,6 +167,12 @@ impl GenerationSettings {
self
}

/// Additional trait bounds applied to `CliConfig` methods.
pub fn with_cli_bounds(&mut self, derive: impl ToString) -> &mut Self {
self.extra_cli_bounds.push(derive.to_string());
self
}

/// Modify a type with the given name.
/// See [typify::TypeSpaceSettings::with_patch].
pub fn with_patch<S: AsRef<str>>(&mut self, type_name: S, patch: &TypePatch) -> &mut Self {
Expand Down
12 changes: 6 additions & 6 deletions progenitor-impl/tests/output/src/buildomat_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -894,23 +894,23 @@ impl<T: CliConfig> Cli<T> {
pub trait CliConfig {
fn success_item<T>(&self, value: &ResponseValue<T>)
where
T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
T: std::clone::Clone + schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
fn success_no_item(&self, value: &ResponseValue<()>);
fn error<T>(&self, value: &Error<T>)
where
T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
T: std::clone::Clone + schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
fn list_start<T>(&self)
where
T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
T: std::clone::Clone + schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
fn list_item<T>(&self, value: &T)
where
T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
T: std::clone::Clone + schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
fn list_end_success<T>(&self)
where
T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
T: std::clone::Clone + 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;
T: std::clone::Clone + schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
fn execute_control_hold(
&self,
matches: &::clap::ArgMatches,
Expand Down
12 changes: 6 additions & 6 deletions progenitor-impl/tests/output/src/cli_gen_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,23 +78,23 @@ impl<T: CliConfig> Cli<T> {
pub trait CliConfig {
fn success_item<T>(&self, value: &ResponseValue<T>)
where
T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
T: std::clone::Clone + schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
fn success_no_item(&self, value: &ResponseValue<()>);
fn error<T>(&self, value: &Error<T>)
where
T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
T: std::clone::Clone + schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
fn list_start<T>(&self)
where
T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
T: std::clone::Clone + schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
fn list_item<T>(&self, value: &T)
where
T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
T: std::clone::Clone + schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
fn list_end_success<T>(&self)
where
T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
T: std::clone::Clone + 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;
T: std::clone::Clone + schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
fn execute_uno(
&self,
matches: &::clap::ArgMatches,
Expand Down
12 changes: 6 additions & 6 deletions progenitor-impl/tests/output/src/keeper_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,23 +381,23 @@ impl<T: CliConfig> Cli<T> {
pub trait CliConfig {
fn success_item<T>(&self, value: &ResponseValue<T>)
where
T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
T: std::clone::Clone + schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
fn success_no_item(&self, value: &ResponseValue<()>);
fn error<T>(&self, value: &Error<T>)
where
T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
T: std::clone::Clone + schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
fn list_start<T>(&self)
where
T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
T: std::clone::Clone + schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
fn list_item<T>(&self, value: &T)
where
T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
T: std::clone::Clone + schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
fn list_end_success<T>(&self)
where
T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
T: std::clone::Clone + 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;
T: std::clone::Clone + schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
fn execute_enrol(
&self,
matches: &::clap::ArgMatches,
Expand Down
12 changes: 6 additions & 6 deletions progenitor-impl/tests/output/src/nexus_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12375,23 +12375,23 @@ impl<T: CliConfig> Cli<T> {
pub trait CliConfig {
fn success_item<T>(&self, value: &ResponseValue<T>)
where
T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
T: std::clone::Clone + schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
fn success_no_item(&self, value: &ResponseValue<()>);
fn error<T>(&self, value: &Error<T>)
where
T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
T: std::clone::Clone + schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
fn list_start<T>(&self)
where
T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
T: std::clone::Clone + schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
fn list_item<T>(&self, value: &T)
where
T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
T: std::clone::Clone + schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
fn list_end_success<T>(&self)
where
T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
T: std::clone::Clone + 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;
T: std::clone::Clone + schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
fn execute_disk_view_by_id(
&self,
matches: &::clap::ArgMatches,
Expand Down
12 changes: 6 additions & 6 deletions progenitor-impl/tests/output/src/param_collision_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,23 +116,23 @@ impl<T: CliConfig> Cli<T> {
pub trait CliConfig {
fn success_item<T>(&self, value: &ResponseValue<T>)
where
T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
T: std::clone::Clone + schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
fn success_no_item(&self, value: &ResponseValue<()>);
fn error<T>(&self, value: &Error<T>)
where
T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
T: std::clone::Clone + schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
fn list_start<T>(&self)
where
T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
T: std::clone::Clone + schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
fn list_item<T>(&self, value: &T)
where
T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
T: std::clone::Clone + schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
fn list_end_success<T>(&self)
where
T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
T: std::clone::Clone + 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;
T: std::clone::Clone + schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
fn execute_key_get(
&self,
matches: &::clap::ArgMatches,
Expand Down
12 changes: 6 additions & 6 deletions progenitor-impl/tests/output/src/param_overrides_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,23 +72,23 @@ impl<T: CliConfig> Cli<T> {
pub trait CliConfig {
fn success_item<T>(&self, value: &ResponseValue<T>)
where
T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
T: std::clone::Clone + schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
fn success_no_item(&self, value: &ResponseValue<()>);
fn error<T>(&self, value: &Error<T>)
where
T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
T: std::clone::Clone + schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
fn list_start<T>(&self)
where
T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
T: std::clone::Clone + schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
fn list_item<T>(&self, value: &T)
where
T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
T: std::clone::Clone + schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
fn list_end_success<T>(&self)
where
T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
T: std::clone::Clone + 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;
T: std::clone::Clone + schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
fn execute_key_get(
&self,
matches: &::clap::ArgMatches,
Expand Down
12 changes: 6 additions & 6 deletions progenitor-impl/tests/output/src/propolis_server_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,23 +343,23 @@ impl<T: CliConfig> Cli<T> {
pub trait CliConfig {
fn success_item<T>(&self, value: &ResponseValue<T>)
where
T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
T: std::clone::Clone + schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
fn success_no_item(&self, value: &ResponseValue<()>);
fn error<T>(&self, value: &Error<T>)
where
T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
T: std::clone::Clone + schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
fn list_start<T>(&self)
where
T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
T: std::clone::Clone + schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
fn list_item<T>(&self, value: &T)
where
T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
T: std::clone::Clone + schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
fn list_end_success<T>(&self)
where
T: schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
T: std::clone::Clone + 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;
T: std::clone::Clone + schemars::JsonSchema + serde::Serialize + std::fmt::Debug;
fn execute_instance_get(
&self,
matches: &::clap::ArgMatches,
Expand Down
1 change: 1 addition & 0 deletions progenitor-impl/tests/test_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ fn verify_apis(openapi_file: &str) {
let mut generator = Generator::new(
GenerationSettings::default()
.with_interface(InterfaceStyle::Builder)
.with_cli_bounds("std::clone::Clone")
.with_tag(TagStyle::Separate),
);
let output = generate_formatted(&mut generator, &spec);
Expand Down
Loading