Skip to content

Commit 43299cc

Browse files
authored
upgrade clap (#1261)
1 parent 1764399 commit 43299cc

16 files changed

+181
-241
lines changed

integration-testing/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ logging = ["tracing-subscriber"]
3434
arrow = { path = "../arrow" }
3535
arrow-flight = { path = "../arrow-flight" }
3636
async-trait = "0.1.41"
37-
clap = "2.33"
37+
clap = { version = "3", features = ["derive", "env"] }
3838
futures = "0.3"
3939
hex = "0.4"
4040
prost = "0.9"

integration-testing/src/bin/arrow-file-to-stream.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,22 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18-
use std::env;
19-
use std::fs::File;
20-
use std::io::{self, BufReader};
21-
2218
use arrow::error::Result;
2319
use arrow::ipc::reader::FileReader;
2420
use arrow::ipc::writer::StreamWriter;
21+
use clap::Parser;
22+
use std::fs::File;
23+
use std::io::{self, BufReader};
24+
25+
#[derive(Debug, Parser)]
26+
#[clap(author, version, about("Read an arrow file and stream to stdout"), long_about = None)]
27+
struct Args {
28+
file_name: String,
29+
}
2530

2631
fn main() -> Result<()> {
27-
let args: Vec<String> = env::args().collect();
28-
let filename = &args[1];
29-
let f = File::open(filename)?;
32+
let args = Args::parse();
33+
let f = File::open(&args.file_name)?;
3034
let reader = BufReader::new(f);
3135
let mut reader = FileReader::try_new(reader)?;
3236
let schema = reader.schema();

integration-testing/src/bin/arrow-json-integration-test.rs

Lines changed: 33 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -15,52 +15,46 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18-
use std::fs::File;
19-
20-
use clap::{App, Arg};
21-
2218
use arrow::error::{ArrowError, Result};
2319
use arrow::ipc::reader::FileReader;
2420
use arrow::ipc::writer::FileWriter;
2521
use arrow::util::integration_util::*;
2622
use arrow_integration_testing::read_json_file;
23+
use clap::Parser;
24+
use std::fs::File;
25+
26+
#[derive(clap::ArgEnum, Debug, Clone)]
27+
#[clap(rename_all = "SCREAMING_SNAKE_CASE")]
28+
enum Mode {
29+
ArrowToJson,
30+
JsonToArrow,
31+
Validate,
32+
}
33+
34+
#[derive(Debug, Parser)]
35+
#[clap(author, version, about("rust arrow-json-integration-test"), long_about = None)]
36+
struct Args {
37+
#[clap(short, long)]
38+
integration: bool,
39+
#[clap(short, long, help("Path to ARROW file"))]
40+
arrow: String,
41+
#[clap(short, long, help("Path to JSON file"))]
42+
json: String,
43+
#[clap(arg_enum, short, long, default_value_t = Mode::Validate, help="Mode of integration testing tool")]
44+
mode: Mode,
45+
#[clap(short, long)]
46+
verbose: bool,
47+
}
2748

2849
fn main() -> Result<()> {
29-
let matches = App::new("rust arrow-json-integration-test")
30-
.arg(Arg::with_name("integration")
31-
.long("integration"))
32-
.arg(Arg::with_name("arrow")
33-
.long("arrow")
34-
.help("path to ARROW file")
35-
.takes_value(true))
36-
.arg(Arg::with_name("json")
37-
.long("json")
38-
.help("path to JSON file")
39-
.takes_value(true))
40-
.arg(Arg::with_name("mode")
41-
.long("mode")
42-
.help("mode of integration testing tool (ARROW_TO_JSON, JSON_TO_ARROW, VALIDATE)")
43-
.takes_value(true)
44-
.default_value("VALIDATE"))
45-
.arg(Arg::with_name("verbose")
46-
.long("verbose")
47-
.help("enable/disable verbose mode"))
48-
.get_matches();
49-
50-
let arrow_file = matches
51-
.value_of("arrow")
52-
.expect("must provide path to arrow file");
53-
let json_file = matches
54-
.value_of("json")
55-
.expect("must provide path to json file");
56-
let mode = matches.value_of("mode").unwrap();
57-
let verbose = true; //matches.value_of("verbose").is_some();
58-
59-
match mode {
60-
"JSON_TO_ARROW" => json_to_arrow(json_file, arrow_file, verbose),
61-
"ARROW_TO_JSON" => arrow_to_json(arrow_file, json_file, verbose),
62-
"VALIDATE" => validate(arrow_file, json_file, verbose),
63-
_ => panic!("mode {} not supported", mode),
50+
let args = Args::parse();
51+
let arrow_file = args.arrow;
52+
let json_file = args.json;
53+
let verbose = args.verbose;
54+
match args.mode {
55+
Mode::JsonToArrow => json_to_arrow(&json_file, &arrow_file, verbose),
56+
Mode::ArrowToJson => arrow_to_json(&arrow_file, &json_file, verbose),
57+
Mode::Validate => validate(&arrow_file, &json_file, verbose),
6458
}
6559
}
6660

integration-testing/src/bin/flight-test-integration-client.rs

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,44 +16,53 @@
1616
// under the License.
1717

1818
use arrow_integration_testing::flight_client_scenarios;
19-
20-
use clap::{App, Arg};
21-
19+
use clap::Parser;
2220
type Error = Box<dyn std::error::Error + Send + Sync + 'static>;
2321
type Result<T = (), E = Error> = std::result::Result<T, E>;
2422

23+
#[derive(clap::ArgEnum, Debug, Clone)]
24+
enum Scenario {
25+
Middleware,
26+
#[clap(name = "auth:basic_proto")]
27+
AuthBasicProto,
28+
}
29+
30+
#[derive(Debug, Parser)]
31+
#[clap(author, version, about("rust flight-test-integration-client"), long_about = None)]
32+
struct Args {
33+
#[clap(long, help = "host of flight server")]
34+
host: String,
35+
#[clap(long, help = "port of flight server")]
36+
port: u16,
37+
#[clap(
38+
short,
39+
long,
40+
help = "path to the descriptor file, only used when scenario is not provided"
41+
)]
42+
path: Option<String>,
43+
#[clap(long, arg_enum)]
44+
scenario: Option<Scenario>,
45+
}
46+
2547
#[tokio::main]
2648
async fn main() -> Result {
2749
#[cfg(feature = "logging")]
2850
tracing_subscriber::fmt::init();
2951

30-
let matches = App::new("rust flight-test-integration-client")
31-
.arg(Arg::with_name("host").long("host").takes_value(true))
32-
.arg(Arg::with_name("port").long("port").takes_value(true))
33-
.arg(Arg::with_name("path").long("path").takes_value(true))
34-
.arg(
35-
Arg::with_name("scenario")
36-
.long("scenario")
37-
.takes_value(true),
38-
)
39-
.get_matches();
40-
41-
let host = matches.value_of("host").expect("Host is required");
42-
let port = matches.value_of("port").expect("Port is required");
52+
let args = Args::parse();
53+
let host = args.host;
54+
let port = args.port;
4355

44-
match matches.value_of("scenario") {
45-
Some("middleware") => {
46-
flight_client_scenarios::middleware::run_scenario(host, port).await?
56+
match args.scenario {
57+
Some(Scenario::Middleware) => {
58+
flight_client_scenarios::middleware::run_scenario(&host, port).await?
4759
}
48-
Some("auth:basic_proto") => {
49-
flight_client_scenarios::auth_basic_proto::run_scenario(host, port).await?
60+
Some(Scenario::AuthBasicProto) => {
61+
flight_client_scenarios::auth_basic_proto::run_scenario(&host, port).await?
5062
}
51-
Some(scenario_name) => unimplemented!("Scenario not found: {}", scenario_name),
5263
None => {
53-
let path = matches
54-
.value_of("path")
55-
.expect("Path is required if scenario is not specified");
56-
flight_client_scenarios::integration_test::run_scenario(host, port, path)
64+
let path = args.path.expect("No path is given");
65+
flight_client_scenarios::integration_test::run_scenario(&host, port, &path)
5766
.await?;
5867
}
5968
}

integration-testing/src/bin/flight-test-integration-server.rs

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,38 +15,43 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18-
use clap::{App, Arg};
19-
2018
use arrow_integration_testing::flight_server_scenarios;
19+
use clap::Parser;
2120

2221
type Error = Box<dyn std::error::Error + Send + Sync + 'static>;
2322
type Result<T = (), E = Error> = std::result::Result<T, E>;
2423

24+
#[derive(clap::ArgEnum, Debug, Clone)]
25+
enum Scenario {
26+
Middleware,
27+
#[clap(name = "auth:basic_proto")]
28+
AuthBasicProto,
29+
}
30+
31+
#[derive(Debug, Parser)]
32+
#[clap(author, version, about("rust flight-test-integration-server"), long_about = None)]
33+
struct Args {
34+
#[clap(long)]
35+
port: u16,
36+
#[clap(long, arg_enum)]
37+
scenario: Option<Scenario>,
38+
}
39+
2540
#[tokio::main]
2641
async fn main() -> Result {
2742
#[cfg(feature = "logging")]
2843
tracing_subscriber::fmt::init();
2944

30-
let matches = App::new("rust flight-test-integration-server")
31-
.about("Integration testing server for Flight.")
32-
.arg(Arg::with_name("port").long("port").takes_value(true))
33-
.arg(
34-
Arg::with_name("scenario")
35-
.long("scenario")
36-
.takes_value(true),
37-
)
38-
.get_matches();
39-
40-
let port = matches.value_of("port").unwrap_or("0");
45+
let args = Args::parse();
46+
let port = args.port;
4147

42-
match matches.value_of("scenario") {
43-
Some("middleware") => {
48+
match args.scenario {
49+
Some(Scenario::Middleware) => {
4450
flight_server_scenarios::middleware::scenario_setup(port).await?
4551
}
46-
Some("auth:basic_proto") => {
52+
Some(Scenario::AuthBasicProto) => {
4753
flight_server_scenarios::auth_basic_proto::scenario_setup(port).await?
4854
}
49-
Some(scenario_name) => unimplemented!("Scenario not found: {}", scenario_name),
5055
None => {
5156
flight_server_scenarios::integration_test::scenario_setup(port).await?;
5257
}

integration-testing/src/flight_client_scenarios/auth_basic_proto.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ type Result<T = (), E = Error> = std::result::Result<T, E>;
2929

3030
type Client = FlightServiceClient<tonic::transport::Channel>;
3131

32-
pub async fn run_scenario(host: &str, port: &str) -> Result {
32+
pub async fn run_scenario(host: &str, port: u16) -> Result {
3333
let url = format!("http://{}:{}", host, port);
3434
let mut client = FlightServiceClient::connect(url).await?;
3535

integration-testing/src/flight_client_scenarios/integration_test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ type Result<T = (), E = Error> = std::result::Result<T, E>;
3838

3939
type Client = FlightServiceClient<tonic::transport::Channel>;
4040

41-
pub async fn run_scenario(host: &str, port: &str, path: &str) -> Result {
41+
pub async fn run_scenario(host: &str, port: u16, path: &str) -> Result {
4242
let url = format!("http://{}:{}", host, port);
4343

4444
let client = FlightServiceClient::connect(url).await?;

integration-testing/src/flight_client_scenarios/middleware.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use tonic::{Request, Status};
2424
type Error = Box<dyn std::error::Error + Send + Sync + 'static>;
2525
type Result<T = (), E = Error> = std::result::Result<T, E>;
2626

27-
pub async fn run_scenario(host: &str, port: &str) -> Result {
27+
pub async fn run_scenario(host: &str, port: u16) -> Result {
2828
let url = format!("http://{}:{}", host, port);
2929
let conn = tonic::transport::Endpoint::new(url)?.connect().await?;
3030
let mut client = FlightServiceClient::with_interceptor(conn, middleware_interceptor);

integration-testing/src/flight_server_scenarios.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub mod middleware;
2727
type Error = Box<dyn std::error::Error + Send + Sync + 'static>;
2828
type Result<T = (), E = Error> = std::result::Result<T, E>;
2929

30-
pub async fn listen_on(port: &str) -> Result<SocketAddr> {
30+
pub async fn listen_on(port: u16) -> Result<SocketAddr> {
3131
let addr: SocketAddr = format!("0.0.0.0:{}", port).parse()?;
3232

3333
let listener = TcpListener::bind(addr).await?;

integration-testing/src/flight_server_scenarios/auth_basic_proto.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use prost::Message;
3737

3838
use crate::{AUTH_PASSWORD, AUTH_USERNAME};
3939

40-
pub async fn scenario_setup(port: &str) -> Result {
40+
pub async fn scenario_setup(port: u16) -> Result {
4141
let service = AuthBasicProtoScenarioImpl {
4242
username: AUTH_USERNAME.into(),
4343
password: AUTH_PASSWORD.into(),

0 commit comments

Comments
 (0)