Skip to content

Commit 636baea

Browse files
committed
add arg to cargo-progenitor
1 parent 090b80b commit 636baea

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

cargo-progenitor/src/main.rs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use std::{
99
use anyhow::{bail, Result};
1010
use clap::{Parser, ValueEnum};
1111
use openapiv3::OpenAPI;
12-
use progenitor::{GenerationSettings, Generator, InterfaceStyle, TagStyle};
12+
use progenitor::{GenerationSettings, Generator, InterfaceStyle, OperationIdStrategy, TagStyle};
1313
use progenitor_impl::space_out_items;
1414

1515
fn is_non_release() -> bool {
@@ -51,6 +51,9 @@ struct Args {
5151
/// SDK tag style
5252
#[clap(value_enum, long, default_value_t = TagArg::Merged)]
5353
tags: TagArg,
54+
/// SDK operation id style
55+
#[clap(value_enum, long, default_value_t = OperationIdStrategyArg::RejectMissing)]
56+
operation_id_strategy: OperationIdStrategyArg,
5457
/// Include client code rather than depending on progenitor-client
5558
#[clap(default_value = match is_non_release() { true => "true", false => "false" }, long, action = clap::ArgAction::Set)]
5659
include_client: bool,
@@ -86,6 +89,23 @@ impl From<TagArg> for TagStyle {
8689
}
8790
}
8891

92+
#[derive(Copy, Clone, ValueEnum)]
93+
enum OperationIdStrategyArg {
94+
RejectMissing,
95+
OmitMissing,
96+
GenerateMissing,
97+
}
98+
99+
impl From<OperationIdStrategyArg> for OperationIdStrategy {
100+
fn from(arg: OperationIdStrategyArg) -> Self {
101+
match arg {
102+
OperationIdStrategyArg::RejectMissing => OperationIdStrategy::RejectMissing,
103+
OperationIdStrategyArg::OmitMissing => OperationIdStrategy::OmitMissing,
104+
OperationIdStrategyArg::GenerateMissing => OperationIdStrategy::GenerateMissing,
105+
}
106+
}
107+
}
108+
89109
fn reformat_code(input: String) -> String {
90110
let config = rustfmt_wrapper::config::Config {
91111
normalize_doc_attributes: Some(true),
@@ -119,7 +139,8 @@ fn main() -> Result<()> {
119139
let mut builder = Generator::new(
120140
GenerationSettings::default()
121141
.with_interface(args.interface.into())
122-
.with_tag(args.tags.into()),
142+
.with_tag(args.tags.into())
143+
.with_operation_id_strategy(args.operation_id_strategy.into()),
123144
);
124145

125146
match builder.generate_tokens(&api) {

0 commit comments

Comments
 (0)