@@ -14,45 +14,11 @@ use clap::Parser;
1414use oapi_codegen:: Config ;
1515use oapi_codegen:: Error ;
1616use oapi_codegen:: Result ;
17+ use oapi_codegen:: cli:: Cli ;
1718use oapi_codegen:: config:: Generate ;
1819
1920use crate :: console:: SpecStats ;
2021
21- /// Extra `--help` text with worked examples.
22- const EXAMPLES : & str = "\
23- Examples:
24- # Write generated code, selecting artifacts in the config file:
25- oapi-codegen api.yaml --config oapi-codegen.yaml --output src/api.rs
26-
27- # The output path may instead come from the config's `output:` key:
28- oapi-codegen api.yaml --config oapi-codegen.yaml
29-
30- A config file is required, must enable at least one artifact, and an output
31- path must be given via --output or the config's `output:` key:
32- # oapi-codegen.yaml
33- output: src/api.rs
34- generate:
35- models: true
36- std-http-server: true
37- client: true" ;
38-
39- /// Generate idiomatic Rust from an OpenAPI 3 specification.
40- #[ derive( Debug , Parser ) ]
41- #[ command( name = "oapi-codegen" , version, about, after_long_help = EXAMPLES ) ]
42- struct Cli {
43- /// Path to the OpenAPI 3 specification (YAML or JSON).
44- spec : PathBuf ,
45-
46- /// Path to an `oapi-codegen` YAML config file (required).
47- #[ arg( short, long) ]
48- config : PathBuf ,
49-
50- /// Output file path (overrides the config `output`). Required unless the
51- /// config sets `output`.
52- #[ arg( short, long) ]
53- output : Option < PathBuf > ,
54- }
55-
5622/// A failure that has enough context to be reported to the user.
5723enum CliFailure {
5824 /// A generator/loader error occurred.
@@ -116,7 +82,7 @@ fn main() -> ExitCode {
11682
11783/// Run the generator according to the parsed CLI arguments.
11884fn run ( cli : & Cli ) -> std:: result:: Result < ( ) , CliFailure > {
119- let config = Config :: load ( & cli. config ) ?;
85+ let config = Config :: load ( & cli. config_file ) ?;
12086
12187 if config. generate . embedded_spec {
12288 return Err ( CliFailure :: Generator ( Error :: Unimplemented ( "embedded-spec" . to_owned ( ) ) ) ) ;
@@ -125,20 +91,20 @@ fn run(cli: &Cli) -> std::result::Result<(), CliFailure> {
12591 let generate = & config. generate ;
12692 if !generate. models && !generate. std_http_server && !generate. client && !generate. server_urls {
12793 return Err ( CliFailure :: NoArtifacts {
128- config : cli. config . clone ( ) ,
94+ config : cli. config_file . clone ( ) ,
12995 } ) ;
13096 }
13197
132- let output = cli. output . clone ( ) . or_else ( || {
98+ let output = cli. output_file . clone ( ) . or_else ( || {
13399 return config. output . clone ( ) ;
134100 } ) ;
135101 let output = output. ok_or ( CliFailure :: NoOutput ) ?;
136102
137- let code = oapi_codegen:: generate ( & cli. spec , & config) ?;
103+ let code = oapi_codegen:: generate ( & cli. spec_file , & config) ?;
138104 if console:: is_effectively_empty ( & code) {
139- let stats = spec_stats ( & cli. spec , & config) ?;
105+ let stats = spec_stats ( & cli. spec_file , & config) ?;
140106 return Err ( CliFailure :: EmptyOutput {
141- spec : cli. spec . clone ( ) ,
107+ spec : cli. spec_file . clone ( ) ,
142108 stats,
143109 generate : config. generate . clone ( ) ,
144110 } ) ;
0 commit comments