Skip to content

Commit 143c948

Browse files
authored
Merge pull request #409 from tranzystorek-io/clap-v3
2 parents 5c8ec75 + 55633eb commit 143c948

File tree

4 files changed

+28
-30
lines changed

4 files changed

+28
-30
lines changed

examples/github/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ graphql_client = { path = "../../graphql_client", features = ["reqwest-blocking"
1010
serde = "^1.0"
1111
reqwest = { version = "^0.11", features = ["json", "blocking"] }
1212
prettytable-rs = "^0.7"
13-
structopt = "^0.3"
13+
clap = { version = "^3.0", features = ["derive"] }
1414
log = "^0.4"
1515
env_logger = "^0.5"

examples/github/examples/github.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use ::reqwest::blocking::Client;
22
use anyhow::*;
3+
use clap::Parser;
34
use graphql_client::{reqwest::post_graphql_blocking as post_graphql, GraphQLQuery};
45
use log::*;
56
use prettytable::*;
6-
use structopt::StructOpt;
77

88
#[allow(clippy::upper_case_acronyms)]
99
type URI = String;
@@ -16,10 +16,10 @@ type URI = String;
1616
)]
1717
struct RepoView;
1818

19-
#[derive(StructOpt)]
20-
#[structopt(author, about)]
19+
#[derive(Parser)]
20+
#[clap(author, about, version)]
2121
struct Command {
22-
#[structopt(name = "repository")]
22+
#[clap(name = "repository")]
2323
repo: String,
2424
}
2525

@@ -37,7 +37,7 @@ fn main() -> Result<(), anyhow::Error> {
3737
let github_api_token =
3838
std::env::var("GITHUB_API_TOKEN").expect("Missing GITHUB_API_TOKEN env var");
3939

40-
let args = Command::from_args();
40+
let args = Command::parse();
4141

4242
let repo = args.repo;
4343
let (owner, name) = parse_repo_name(&repo).unwrap_or(("tomhoule", "graphql-client"));

graphql_client_cli/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ path = "src/main.rs"
1515
reqwest = { version = "^0.11", features = ["json", "blocking"] }
1616
graphql_client = { version = "0.10.0", path = "../graphql_client", default-features = false, features = ["graphql_query_derive", "reqwest-blocking"] }
1717
graphql_client_codegen = { path = "../graphql_client_codegen/", version = "0.10.0" }
18-
structopt = "0.3"
18+
clap = { version = "^3.0", features = ["derive"] }
1919
serde = { version = "^1.0", features = ["derive"] }
2020
serde_json = "^1.0"
2121
log = "^0.4"

graphql_client_cli/src/main.rs

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,93 +1,91 @@
1-
#![allow(clippy::redundant_clone)] // in structopt generated code
2-
31
mod error;
42
mod generate;
53
mod introspect_schema;
64

5+
use clap::Parser;
76
use env_logger::fmt::{Color, Style, StyledValue};
87
use error::Error;
98
use log::Level;
109
use std::path::PathBuf;
11-
use structopt::StructOpt;
1210
use Cli::Generate;
1311

1412
type CliResult<T> = Result<T, Error>;
1513

16-
#[derive(StructOpt)]
17-
#[structopt(author, about)]
14+
#[derive(Parser)]
15+
#[clap(author, about, version)]
1816
enum Cli {
1917
/// Get the schema from a live GraphQL API. The schema is printed to stdout.
20-
#[structopt(name = "introspect-schema")]
18+
#[clap(name = "introspect-schema")]
2119
IntrospectSchema {
2220
/// The URL of a GraphQL endpoint to introspect.
2321
schema_location: String,
2422
/// 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")]
2725
output: Option<PathBuf>,
2826
/// Set the contents of the Authorizaiton header.
29-
#[structopt(long = "authorization")]
27+
#[clap(long = "authorization")]
3028
authorization: Option<String>,
3129
/// Specify custom headers.
3230
/// --header 'X-Name: Value'
33-
#[structopt(long = "header")]
31+
#[clap(long = "header")]
3432
headers: Vec<introspect_schema::Header>,
3533
/// Disable ssl verification.
3634
/// Default value is false.
37-
#[structopt(long = "no-ssl")]
35+
#[clap(long = "no-ssl")]
3836
no_ssl: bool,
3937
},
40-
#[structopt(name = "generate")]
38+
#[clap(name = "generate")]
4139
Generate {
4240
/// Path to GraphQL schema file (.json or .graphql).
43-
#[structopt(short = "s", long = "schema-path")]
41+
#[clap(short = 's', long = "schema-path")]
4442
schema_path: PathBuf,
4543
/// Path to the GraphQL query file.
4644
query_path: PathBuf,
4745
/// 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")]
4947
selected_operation: Option<String>,
5048
/// Additional derives that will be added to the generated structs and enums for the variables.
5149
/// --variables-derives='Serialize,PartialEq'
52-
#[structopt(short = "I", long = "variables-derives")]
50+
#[clap(short = 'I', long = "variables-derives")]
5351
variables_derives: Option<String>,
5452
/// Additional derives that will be added to the generated structs and enums for the response.
5553
/// --output-derives='Serialize,PartialEq'
56-
#[structopt(short = "O", long = "response-derives")]
54+
#[clap(short = 'O', long = "response-derives")]
5755
response_derives: Option<String>,
5856
/// You can choose deprecation strategy from allow, deny, or warn.
5957
/// Default value is warn.
60-
#[structopt(short = "d", long = "deprecation-strategy")]
58+
#[clap(short = 'd', long = "deprecation-strategy")]
6159
deprecation_strategy: Option<String>,
6260
/// If you don't want to execute rustfmt to generated code, set this option.
6361
/// Default value is false.
64-
#[structopt(long = "no-formatting")]
62+
#[clap(long = "no-formatting")]
6563
no_formatting: bool,
6664
/// You can choose module and target struct visibility from pub and private.
6765
/// Default value is pub.
68-
#[structopt(short = "m", long = "module-visibility")]
66+
#[clap(short = 'm', long = "module-visibility")]
6967
module_visibility: Option<String>,
7068
/// The directory in which the code will be generated.
7169
///
7270
/// If this option is omitted, the code will be generated next to the .graphql
7371
/// file, with the same name and the .rs extension.
74-
#[structopt(short = "o", long = "output-directory")]
72+
#[clap(short = 'o', long = "output-directory")]
7573
output_directory: Option<PathBuf>,
7674
/// The module where the custom scalar definitions are located.
7775
/// --custom-scalars-module='crate::gql::custom_scalars'
78-
#[structopt(short = "p", long = "custom-scalars-module")]
76+
#[clap(short = 'p', long = "custom-scalars-module")]
7977
custom_scalars_module: Option<String>,
8078
/// A flag indicating if the enum representing the variants of a fragment union/interface should have a "other" variant
8179
/// --fragments-other-variant
82-
#[structopt(long = "fragments-other-variant")]
80+
#[clap(long = "fragments-other-variant")]
8381
fragments_other_variant: bool,
8482
},
8583
}
8684

8785
fn main() -> CliResult<()> {
8886
set_env_logger();
8987

90-
let cli = Cli::from_args();
88+
let cli = Cli::parse();
9189
match cli {
9290
Cli::IntrospectSchema {
9391
schema_location,

0 commit comments

Comments
 (0)