|
1 | | -#![allow(clippy::redundant_clone)] // in structopt generated code |
2 | | - |
3 | 1 | mod error; |
4 | 2 | mod generate; |
5 | 3 | mod introspect_schema; |
6 | 4 |
|
| 5 | +use clap::Parser; |
7 | 6 | use env_logger::fmt::{Color, Style, StyledValue}; |
8 | 7 | use error::Error; |
9 | 8 | use log::Level; |
10 | 9 | use std::path::PathBuf; |
11 | | -use structopt::StructOpt; |
12 | 10 | use Cli::Generate; |
13 | 11 |
|
14 | 12 | type CliResult<T> = Result<T, Error>; |
15 | 13 |
|
16 | | -#[derive(StructOpt)] |
17 | | -#[structopt(author, about)] |
| 14 | +#[derive(Parser)] |
| 15 | +#[clap(author, about, version)] |
18 | 16 | enum Cli { |
19 | 17 | /// Get the schema from a live GraphQL API. The schema is printed to stdout. |
20 | | - #[structopt(name = "introspect-schema")] |
| 18 | + #[clap(name = "introspect-schema")] |
21 | 19 | IntrospectSchema { |
22 | 20 | /// The URL of a GraphQL endpoint to introspect. |
23 | 21 | schema_location: String, |
24 | 22 | /// Where to write the JSON for the introspected schema. |
25 | | - #[structopt(parse(from_os_str))] |
26 | | - #[structopt(long = "output")] |
| 23 | + #[clap(parse(from_os_str))] |
| 24 | + #[clap(long = "output")] |
27 | 25 | output: Option<PathBuf>, |
28 | 26 | /// Set the contents of the Authorizaiton header. |
29 | | - #[structopt(long = "authorization")] |
| 27 | + #[clap(long = "authorization")] |
30 | 28 | authorization: Option<String>, |
31 | 29 | /// Specify custom headers. |
32 | 30 | /// --header 'X-Name: Value' |
33 | | - #[structopt(long = "header")] |
| 31 | + #[clap(long = "header")] |
34 | 32 | headers: Vec<introspect_schema::Header>, |
35 | 33 | /// Disable ssl verification. |
36 | 34 | /// Default value is false. |
37 | | - #[structopt(long = "no-ssl")] |
| 35 | + #[clap(long = "no-ssl")] |
38 | 36 | no_ssl: bool, |
39 | 37 | }, |
40 | | - #[structopt(name = "generate")] |
| 38 | + #[clap(name = "generate")] |
41 | 39 | Generate { |
42 | 40 | /// Path to GraphQL schema file (.json or .graphql). |
43 | | - #[structopt(short = "s", long = "schema-path")] |
| 41 | + #[clap(short = 's', long = "schema-path")] |
44 | 42 | schema_path: PathBuf, |
45 | 43 | /// Path to the GraphQL query file. |
46 | 44 | query_path: PathBuf, |
47 | 45 | /// Name of target query. If you don't set this parameter, cli generate all queries in query file. |
48 | | - #[structopt(long = "selected-operation")] |
| 46 | + #[clap(long = "selected-operation")] |
49 | 47 | selected_operation: Option<String>, |
50 | 48 | /// Additional derives that will be added to the generated structs and enums for the variables. |
51 | 49 | /// --variables-derives='Serialize,PartialEq' |
52 | | - #[structopt(short = "I", long = "variables-derives")] |
| 50 | + #[clap(short = 'I', long = "variables-derives")] |
53 | 51 | variables_derives: Option<String>, |
54 | 52 | /// Additional derives that will be added to the generated structs and enums for the response. |
55 | 53 | /// --output-derives='Serialize,PartialEq' |
56 | | - #[structopt(short = "O", long = "response-derives")] |
| 54 | + #[clap(short = 'O', long = "response-derives")] |
57 | 55 | response_derives: Option<String>, |
58 | 56 | /// You can choose deprecation strategy from allow, deny, or warn. |
59 | 57 | /// Default value is warn. |
60 | | - #[structopt(short = "d", long = "deprecation-strategy")] |
| 58 | + #[clap(short = 'd', long = "deprecation-strategy")] |
61 | 59 | deprecation_strategy: Option<String>, |
62 | 60 | /// If you don't want to execute rustfmt to generated code, set this option. |
63 | 61 | /// Default value is false. |
64 | | - #[structopt(long = "no-formatting")] |
| 62 | + #[clap(long = "no-formatting")] |
65 | 63 | no_formatting: bool, |
66 | 64 | /// You can choose module and target struct visibility from pub and private. |
67 | 65 | /// Default value is pub. |
68 | | - #[structopt(short = "m", long = "module-visibility")] |
| 66 | + #[clap(short = 'm', long = "module-visibility")] |
69 | 67 | module_visibility: Option<String>, |
70 | 68 | /// The directory in which the code will be generated. |
71 | 69 | /// |
72 | 70 | /// If this option is omitted, the code will be generated next to the .graphql |
73 | 71 | /// file, with the same name and the .rs extension. |
74 | | - #[structopt(short = "o", long = "output-directory")] |
| 72 | + #[clap(short = 'o', long = "output-directory")] |
75 | 73 | output_directory: Option<PathBuf>, |
76 | 74 | /// The module where the custom scalar definitions are located. |
77 | 75 | /// --custom-scalars-module='crate::gql::custom_scalars' |
78 | | - #[structopt(short = "p", long = "custom-scalars-module")] |
| 76 | + #[clap(short = 'p', long = "custom-scalars-module")] |
79 | 77 | custom_scalars_module: Option<String>, |
80 | 78 | /// A flag indicating if the enum representing the variants of a fragment union/interface should have a "other" variant |
81 | 79 | /// --fragments-other-variant |
82 | | - #[structopt(long = "fragments-other-variant")] |
| 80 | + #[clap(long = "fragments-other-variant")] |
83 | 81 | fragments_other_variant: bool, |
84 | 82 | }, |
85 | 83 | } |
86 | 84 |
|
87 | 85 | fn main() -> CliResult<()> { |
88 | 86 | set_env_logger(); |
89 | 87 |
|
90 | | - let cli = Cli::from_args(); |
| 88 | + let cli = Cli::parse(); |
91 | 89 | match cli { |
92 | 90 | Cli::IntrospectSchema { |
93 | 91 | schema_location, |
|
0 commit comments