You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by ji...@apache.org on 2022/02/02 08:29:21 UTC

[arrow-rs] branch upgrade-clap created (now 0f3d315)

This is an automated email from the ASF dual-hosted git repository.

jiayuliu pushed a change to branch upgrade-clap
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git.


      at 0f3d315  upgrade clap

This branch includes the following new commits:

     new 0f3d315  upgrade clap

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


[arrow-rs] 01/01: upgrade clap

Posted by ji...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jiayuliu pushed a commit to branch upgrade-clap
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git

commit 0f3d315938efbcd86aba44c896470c929d620218
Author: Jiayu Liu <ji...@hey.com>
AuthorDate: Wed Feb 2 16:29:10 2022 +0800

    upgrade clap
---
 integration-testing/Cargo.toml                     |  2 +-
 .../src/bin/arrow-json-integration-test.rs         | 70 ++++++++++------------
 .../src/bin/flight-test-integration-client.rs      | 12 ++--
 .../src/bin/flight-test-integration-server.rs      |  8 +--
 parquet/Cargo.toml                                 |  2 +-
 5 files changed, 41 insertions(+), 53 deletions(-)

diff --git a/integration-testing/Cargo.toml b/integration-testing/Cargo.toml
index cbb6ca6..292f485 100644
--- a/integration-testing/Cargo.toml
+++ b/integration-testing/Cargo.toml
@@ -34,7 +34,7 @@ logging = ["tracing-subscriber"]
 arrow = { path = "../arrow" }
 arrow-flight = { path = "../arrow-flight" }
 async-trait = "0.1.41"
-clap = "2.33"
+clap = { version = "3", features = ["derive"] }
 futures = "0.3"
 hex = "0.4"
 prost = "0.9"
diff --git a/integration-testing/src/bin/arrow-json-integration-test.rs b/integration-testing/src/bin/arrow-json-integration-test.rs
index 2578020..1047936 100644
--- a/integration-testing/src/bin/arrow-json-integration-test.rs
+++ b/integration-testing/src/bin/arrow-json-integration-test.rs
@@ -15,52 +15,48 @@
 // specific language governing permissions and limitations
 // under the License.
 
-use std::fs::File;
-
-use clap::{App, Arg};
-
 use arrow::error::{ArrowError, Result};
 use arrow::ipc::reader::FileReader;
 use arrow::ipc::writer::FileWriter;
 use arrow::util::integration_util::*;
 use arrow_integration_testing::read_json_file;
+use clap::Parser;
+use std::fs::File;
+
+#[derive(clap::ArgEnum, Debug, Clone)]
+enum Mode {
+    ArrowToJson,
+    JsonToArrow,
+    Validate,
+}
+
+#[derive(Debug, Parser)]
+#[clap( author, version, about, long_about = None)]
+struct Args {
+    #[clap(long, help("The path to the JSON file to read."))]
+    integration: String,
+    #[clap(long, help("path to ARROW file"))]
+    arrow: String,
+    #[clap(long, help("path to JSON file"))]
+    json: String,
+    #[clap(arg_enum, long, default_value_t = Mode::Validate, help="mode of integration testing tool")]
+    mode: Mode,
+    #[clap(long, help("mode of integration testing tool"))]
+    verbose: bool,
+}
 
 fn main() -> Result<()> {
-    let matches = App::new("rust arrow-json-integration-test")
-        .arg(Arg::with_name("integration")
-            .long("integration"))
-        .arg(Arg::with_name("arrow")
-            .long("arrow")
-            .help("path to ARROW file")
-            .takes_value(true))
-        .arg(Arg::with_name("json")
-            .long("json")
-            .help("path to JSON file")
-            .takes_value(true))
-        .arg(Arg::with_name("mode")
-            .long("mode")
-            .help("mode of integration testing tool (ARROW_TO_JSON, JSON_TO_ARROW, VALIDATE)")
-            .takes_value(true)
-            .default_value("VALIDATE"))
-        .arg(Arg::with_name("verbose")
-            .long("verbose")
-            .help("enable/disable verbose mode"))
-        .get_matches();
-
-    let arrow_file = matches
-        .value_of("arrow")
-        .expect("must provide path to arrow file");
-    let json_file = matches
-        .value_of("json")
-        .expect("must provide path to json file");
-    let mode = matches.value_of("mode").unwrap();
-    let verbose = true; //matches.value_of("verbose").is_some();
+    let args = Args::parse();
+
+    let arrow_file = args.arrow;
+    let json_file = args.json;
+    let mode = args.mode;
+    let verbose = args.verbose;
 
     match mode {
-        "JSON_TO_ARROW" => json_to_arrow(json_file, arrow_file, verbose),
-        "ARROW_TO_JSON" => arrow_to_json(arrow_file, json_file, verbose),
-        "VALIDATE" => validate(arrow_file, json_file, verbose),
-        _ => panic!("mode {} not supported", mode),
+        Mode::JsonToArrow => json_to_arrow(&json_file, &arrow_file, verbose),
+        Mode::ArrowToJson => arrow_to_json(&arrow_file, &json_file, verbose),
+        Mode::Validate => validate(&arrow_file, &json_file, verbose),
     }
 }
 
diff --git a/integration-testing/src/bin/flight-test-integration-client.rs b/integration-testing/src/bin/flight-test-integration-client.rs
index 1901553..a765fee 100644
--- a/integration-testing/src/bin/flight-test-integration-client.rs
+++ b/integration-testing/src/bin/flight-test-integration-client.rs
@@ -28,14 +28,10 @@ async fn main() -> Result {
     tracing_subscriber::fmt::init();
 
     let matches = App::new("rust flight-test-integration-client")
-        .arg(Arg::with_name("host").long("host").takes_value(true))
-        .arg(Arg::with_name("port").long("port").takes_value(true))
-        .arg(Arg::with_name("path").long("path").takes_value(true))
-        .arg(
-            Arg::with_name("scenario")
-                .long("scenario")
-                .takes_value(true),
-        )
+        .arg(Arg::new("host").long("host").takes_value(true))
+        .arg(Arg::new("port").long("port").takes_value(true))
+        .arg(Arg::new("path").long("path").takes_value(true))
+        .arg(Arg::new("scenario").long("scenario").takes_value(true))
         .get_matches();
 
     let host = matches.value_of("host").expect("Host is required");
diff --git a/integration-testing/src/bin/flight-test-integration-server.rs b/integration-testing/src/bin/flight-test-integration-server.rs
index b1b2807..cbe891e 100644
--- a/integration-testing/src/bin/flight-test-integration-server.rs
+++ b/integration-testing/src/bin/flight-test-integration-server.rs
@@ -29,12 +29,8 @@ async fn main() -> Result {
 
     let matches = App::new("rust flight-test-integration-server")
         .about("Integration testing server for Flight.")
-        .arg(Arg::with_name("port").long("port").takes_value(true))
-        .arg(
-            Arg::with_name("scenario")
-                .long("scenario")
-                .takes_value(true),
-        )
+        .arg(Arg::new("port").long("port").takes_value(true))
+        .arg(Arg::new("scenario").long("scenario").takes_value(true))
         .get_matches();
 
     let port = matches.value_of("port").unwrap_or("0");
diff --git a/parquet/Cargo.toml b/parquet/Cargo.toml
index 3255f4b..623d50c 100644
--- a/parquet/Cargo.toml
+++ b/parquet/Cargo.toml
@@ -42,7 +42,7 @@ chrono = { version = "0.4", default-features = false }
 num-bigint = "0.4"
 arrow = { path = "../arrow", version = "8.0.0", optional = true, default-features = false, features = ["ipc"] }
 base64 = { version = "0.13", optional = true }
-clap = { version = "2.33.3", optional = true }
+clap = { version = "3", optional = true, features = ["derive"] }
 serde_json = { version = "1.0", features = ["preserve_order"], optional = true }
 rand = "0.8"