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

houqp pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow-datafusion.git


The following commit(s) were added to refs/heads/master by this push:
     new ee91c68  upgrade clap to version 3 (#1672)
ee91c68 is described below

commit ee91c680ad1acdc4ad6a605954b29ba03c238ae7
Author: Jiayu Liu <[email protected]>
AuthorDate: Wed Jan 26 02:43:06 2022 +0800

    upgrade clap to version 3 (#1672)
    
    * upgrade clap to version 3
    
    * multiple value => multiple occurrances
---
 ballista/rust/core/Cargo.toml      |  2 +-
 ballista/rust/core/src/config.rs   | 18 ++++++++++++------
 ballista/rust/scheduler/Cargo.toml |  2 +-
 ballista/rust/scheduler/src/lib.rs | 18 ++++++++++++------
 datafusion-cli/Cargo.toml          |  2 +-
 datafusion-cli/src/exec.rs         |  1 -
 datafusion-cli/src/main.rs         | 34 +++++++++++++++++-----------------
 7 files changed, 44 insertions(+), 33 deletions(-)

diff --git a/ballista/rust/core/Cargo.toml b/ballista/rust/core/Cargo.toml
index 5f566e4..fa68be6 100644
--- a/ballista/rust/core/Cargo.toml
+++ b/ballista/rust/core/Cargo.toml
@@ -42,7 +42,7 @@ tokio = "1.0"
 tonic = "0.6"
 uuid = { version = "0.8", features = ["v4"] }
 chrono = { version = "0.4", default-features = false }
-clap = "2"
+clap = { version = "3", features = ["derive", "cargo"] }
 parse_arg = "0.1.3"
 
 arrow-flight = { version = "8.0.0"  }
diff --git a/ballista/rust/core/src/config.rs b/ballista/rust/core/src/config.rs
index 12e50e2..fa60231 100644
--- a/ballista/rust/core/src/config.rs
+++ b/ballista/rust/core/src/config.rs
@@ -18,7 +18,7 @@
 
 //! Ballista configuration
 
-use clap::arg_enum;
+use clap::ArgEnum;
 use core::fmt;
 use std::collections::HashMap;
 use std::result;
@@ -199,11 +199,17 @@ impl BallistaConfig {
 
 // an enum used to configure the scheduler policy
 // needs to be visible to code generated by configure_me
-arg_enum! {
-    #[derive(Clone, Copy, Debug, serde::Deserialize)]
-    pub enum TaskSchedulingPolicy {
-        PullStaged,
-        PushStaged,
+#[derive(Clone, ArgEnum, Copy, Debug, serde::Deserialize)]
+pub enum TaskSchedulingPolicy {
+    PullStaged,
+    PushStaged,
+}
+
+impl std::str::FromStr for TaskSchedulingPolicy {
+    type Err = String;
+
+    fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
+        ArgEnum::from_str(s, true)
     }
 }
 
diff --git a/ballista/rust/scheduler/Cargo.toml 
b/ballista/rust/scheduler/Cargo.toml
index d357f6f..10b3723 100644
--- a/ballista/rust/scheduler/Cargo.toml
+++ b/ballista/rust/scheduler/Cargo.toml
@@ -33,7 +33,7 @@ sled = ["sled_package", "tokio-stream"]
 [dependencies]
 anyhow = "1"
 ballista-core = { path = "../core", version = "0.6.0" }
-clap = "2"
+clap = { version = "3", features = ["derive", "cargo"] }
 configure_me = "0.4.0"
 datafusion = { path = "../../../datafusion", version = "6.0.0" }
 env_logger = "0.9"
diff --git a/ballista/rust/scheduler/src/lib.rs 
b/ballista/rust/scheduler/src/lib.rs
index 4b2f178..cc508d3 100644
--- a/ballista/rust/scheduler/src/lib.rs
+++ b/ballista/rust/scheduler/src/lib.rs
@@ -59,7 +59,7 @@ use ballista_core::serde::scheduler::{
     ExecutorData, ExecutorMeta, ExecutorSpecification,
 };
 
-use clap::arg_enum;
+use clap::ArgEnum;
 use datafusion::physical_plan::ExecutionPlan;
 
 #[cfg(feature = "sled")]
@@ -67,11 +67,17 @@ extern crate sled_package as sled;
 
 // an enum used to configure the backend
 // needs to be visible to code generated by configure_me
-arg_enum! {
-    #[derive(Debug, serde::Deserialize)]
-    pub enum ConfigBackend {
-        Etcd,
-        Standalone
+#[derive(Debug, Clone, ArgEnum, serde::Deserialize)]
+pub enum ConfigBackend {
+    Etcd,
+    Standalone,
+}
+
+impl std::str::FromStr for ConfigBackend {
+    type Err = String;
+
+    fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
+        ArgEnum::from_str(s, true)
     }
 }
 
diff --git a/datafusion-cli/Cargo.toml b/datafusion-cli/Cargo.toml
index c633859..57afa2f 100644
--- a/datafusion-cli/Cargo.toml
+++ b/datafusion-cli/Cargo.toml
@@ -27,7 +27,7 @@ repository = "https://github.com/apache/arrow-datafusion";
 rust-version = "1.58"
 
 [dependencies]
-clap = "2.33"
+clap = { version = "3", features = ["derive", "cargo"] }
 rustyline = "9.0"
 tokio = { version = "1.0", features = ["macros", "rt", "rt-multi-thread", 
"sync"] }
 datafusion = { path = "../datafusion", version = "6.0.0" }
diff --git a/datafusion-cli/src/exec.rs b/datafusion-cli/src/exec.rs
index 17b7197..dad6d6e 100644
--- a/datafusion-cli/src/exec.rs
+++ b/datafusion-cli/src/exec.rs
@@ -24,7 +24,6 @@ use crate::{
     print_format::{all_print_formats, PrintFormat},
     print_options::PrintOptions,
 };
-use clap::SubCommand;
 use datafusion::arrow::record_batch::RecordBatch;
 use datafusion::arrow::util::pretty;
 use datafusion::error::{DataFusionError, Result};
diff --git a/datafusion-cli/src/main.rs b/datafusion-cli/src/main.rs
index 577a311..4cb9e9d 100644
--- a/datafusion-cli/src/main.rs
+++ b/datafusion-cli/src/main.rs
@@ -40,32 +40,32 @@ pub async fn main() -> Result<()> {
              Parquet files as well as querying directly against in-memory 
data.",
         )
         .arg(
-            Arg::with_name("data-path")
+            Arg::new("data-path")
                 .help("Path to your data, default to current directory")
-                .short("p")
+                .short('p')
                 .long("data-path")
                 .validator(is_valid_data_dir)
                 .takes_value(true),
         )
         .arg(
-            Arg::with_name("batch-size")
+            Arg::new("batch-size")
                 .help("The batch size of each query, or use DataFusion 
default")
-                .short("c")
+                .short('c')
                 .long("batch-size")
                 .validator(is_valid_batch_size)
                 .takes_value(true),
         )
         .arg(
-            Arg::with_name("file")
+            Arg::new("file")
                 .help("Execute commands from file(s), then exit")
-                .short("f")
+                .short('f')
                 .long("file")
-                .multiple(true)
+                .multiple_occurrences(true)
                 .validator(is_valid_file)
                 .takes_value(true),
         )
         .arg(
-            Arg::with_name("format")
+            Arg::new("format")
                 .help("Output format")
                 .long("format")
                 .default_value("table")
@@ -81,21 +81,21 @@ pub async fn main() -> Result<()> {
                 .takes_value(true),
         )
         .arg(
-            Arg::with_name("host")
+            Arg::new("host")
                 .help("Ballista scheduler host")
                 .long("host")
                 .takes_value(true),
         )
         .arg(
-            Arg::with_name("port")
+            Arg::new("port")
                 .help("Ballista scheduler port")
                 .long("port")
                 .takes_value(true),
         )
         .arg(
-            Arg::with_name("quiet")
+            Arg::new("quiet")
                 .help("Reduce printing other than the results and work 
quietly")
-                .short("q")
+                .short('q')
                 .long("quiet")
                 .takes_value(false),
         )
@@ -154,23 +154,23 @@ pub async fn main() -> Result<()> {
     Ok(())
 }
 
-fn is_valid_file(dir: String) -> std::result::Result<(), String> {
-    if Path::new(&dir).is_file() {
+fn is_valid_file(dir: &str) -> std::result::Result<(), String> {
+    if Path::new(dir).is_file() {
         Ok(())
     } else {
         Err(format!("Invalid file '{}'", dir))
     }
 }
 
-fn is_valid_data_dir(dir: String) -> std::result::Result<(), String> {
-    if Path::new(&dir).is_dir() {
+fn is_valid_data_dir(dir: &str) -> std::result::Result<(), String> {
+    if Path::new(dir).is_dir() {
         Ok(())
     } else {
         Err(format!("Invalid data directory '{}'", dir))
     }
 }
 
-fn is_valid_batch_size(size: String) -> std::result::Result<(), String> {
+fn is_valid_batch_size(size: &str) -> std::result::Result<(), String> {
     match size.parse::<usize>() {
         Ok(size) if size > 0 => Ok(()),
         _ => Err(format!("Invalid batch size '{}'", size)),

Reply via email to