upgrade clap to 4 (#304)

This commit is contained in:
QP Hou 2023-10-14 21:09:21 -07:00 committed by GitHub
parent 51584dd3a0
commit ea01ffe0d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 120 additions and 100 deletions

121
Cargo.lock generated
View File

@ -86,6 +86,54 @@ dependencies = [
"libc",
]
[[package]]
name = "anstream"
version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2ab91ebe16eb252986481c5b62f6098f3b698a45e34b5b98200cf20dd2484a44"
dependencies = [
"anstyle",
"anstyle-parse",
"anstyle-query",
"anstyle-wincon",
"colorchoice",
"utf8parse",
]
[[package]]
name = "anstyle"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7079075b41f533b8c61d2a4d073c4676e1f8b249ff94a393b0595db304e0dd87"
[[package]]
name = "anstyle-parse"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "317b9a89c1868f5ea6ff1d9539a69f45dffc21ce321ac1fd1160dfa48c8e2140"
dependencies = [
"utf8parse",
]
[[package]]
name = "anstyle-query"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5ca11d4be1bab0c8bc8734a9aa7bf4ee8316d462a08c6ac5052f888fef5b494b"
dependencies = [
"windows-sys",
]
[[package]]
name = "anstyle-wincon"
version = "3.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0699d10d2f4d628a98ee7b57b289abbc98ff3bad977cb3152709d4bf2330628"
dependencies = [
"anstyle",
"windows-sys",
]
[[package]]
name = "anyhow"
version = "1.0.75"
@ -476,17 +524,6 @@ version = "1.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1181e1e0d1fce796a03db1ae795d67167da795f9cf4a39c37589e85ef57f26d3"
[[package]]
name = "atty"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
dependencies = [
"hermit-abi 0.1.19",
"libc",
"winapi",
]
[[package]]
name = "autocfg"
version = "1.1.0"
@ -902,27 +939,30 @@ dependencies = [
[[package]]
name = "clap"
version = "3.2.25"
version = "4.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ea181bf566f71cb9a5d17a59e1871af638180a18fb0035c92ae62b705207123"
checksum = "d04704f56c2cde07f43e8e2c154b43f216dc5c92fc98ada720177362f953b956"
dependencies = [
"atty",
"bitflags 1.3.2",
"clap_builder",
]
[[package]]
name = "clap_builder"
version = "4.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0e231faeaca65ebd1ea3c737966bf858971cd38c3849107aa3ea7de90a804e45"
dependencies = [
"anstream",
"anstyle",
"clap_lex",
"indexmap 1.9.3",
"strsim",
"termcolor",
"textwrap",
]
[[package]]
name = "clap_lex"
version = "0.2.4"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5"
dependencies = [
"os_str_bytes",
]
checksum = "cd7cc57abe963c6d3b9d8be5b06ba7c8957a930305ca90304f24ef040aa6f961"
[[package]]
name = "clipboard-win"
@ -953,6 +993,12 @@ dependencies = [
"encoding_rs",
]
[[package]]
name = "colorchoice"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7"
[[package]]
name = "columnq"
version = "0.7.0"
@ -966,7 +1012,7 @@ dependencies = [
"dotenvy",
"futures",
"graphql-parser",
"hyper-rustls 0.23.2",
"hyper-rustls 0.24.1",
"hyper-tls",
"lazy_static",
"log",
@ -2136,15 +2182,6 @@ version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
[[package]]
name = "hermit-abi"
version = "0.1.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33"
dependencies = [
"libc",
]
[[package]]
name = "hermit-abi"
version = "0.3.2"
@ -2401,7 +2438,7 @@ version = "1.0.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eae7b9aee968036d54dce06cebaefd919e4472e753296daccd6d344e3e2df0c2"
dependencies = [
"hermit-abi 0.3.2",
"hermit-abi",
"libc",
"windows-sys",
]
@ -2418,7 +2455,7 @@ version = "0.4.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b"
dependencies = [
"hermit-abi 0.3.2",
"hermit-abi",
"rustix 0.38.13",
"windows-sys",
]
@ -2962,7 +2999,7 @@ version = "1.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43"
dependencies = [
"hermit-abi 0.3.2",
"hermit-abi",
"libc",
]
@ -3089,12 +3126,6 @@ dependencies = [
"num-traits",
]
[[package]]
name = "os_str_bytes"
version = "6.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4d5d9eb14b174ee9aa2ef96dc2b94637a2d4b6e7cb873c7e171f0c20c6cf3eac"
[[package]]
name = "owning_ref"
version = "0.4.1"
@ -4622,12 +4653,6 @@ dependencies = [
"winapi-util",
]
[[package]]
name = "textwrap"
version = "0.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "222a222a5bfe1bba4a77b45ec488a741b3cb8872e5e499451fd7d0129c9c7c3d"
[[package]]
name = "thiserror"
version = "1.0.48"

View File

@ -22,7 +22,7 @@ tokio = "1"
rustyline = { version = "9" }
env_logger = { version = "0" }
anyhow = { version = "1" }
clap = { version = "3", features = ["color"] }
clap = { version = "4", features = ["color"] }
dirs = { version = "4" }
[features]

View File

@ -31,13 +31,12 @@ fn config_path() -> anyhow::Result<PathBuf> {
Ok(home)
}
fn table_arg() -> clap::Arg<'static> {
fn table_arg() -> clap::Arg {
clap::Arg::new("table")
.long_help("Table sources to load. Table option can be provided as optional setting as part of the table URI, for example: `blogs=s3://bucket/key,format=delta`. Set table uri to `stdin` if you want to consume table data from stdin as part of a UNIX pipe. If no table_name is provided, a table name will be derived from the filename in URI.")
.takes_value(true)
.num_args(1)
.required(false)
.number_of_values(1)
.multiple_occurrences(true)
.value_name("[table_name=]uri[,option_key=option_value]")
.long("table")
.short('t')
@ -90,7 +89,7 @@ async fn cmd_console(args: &clap::ArgMatches) -> anyhow::Result<()> {
let config = SessionConfig::default().with_information_schema(true);
let mut cq = ColumnQ::new_with_config(config);
if let Some(tables) = args.values_of("table") {
if let Some(tables) = args.get_many::<&str>("table") {
for v in tables {
cq.load_table(&parse_table_uri_arg(v)?).await?;
}
@ -110,33 +109,33 @@ async fn cmd_sql(args: &clap::ArgMatches) -> anyhow::Result<()> {
let config = SessionConfig::default().with_information_schema(true);
let mut cq = ColumnQ::new_with_config(config);
if let Some(tables) = args.values_of("table") {
if let Some(tables) = args.get_many::<&str>("table") {
for v in tables {
cq.load_table(&parse_table_uri_arg(v)?).await?;
}
}
match args.value_of("SQL") {
match args.get_one::<&str>("SQL") {
Some(query) => match cq.query_sql(query).await {
Ok(batches) => match args.value_of("output").unwrap_or("table") {
"table" => pretty::print_batches(&batches)?,
"json" => {
Ok(batches) => match args.get_one::<&str>("output").unwrap_or(&"table") {
&"table" => pretty::print_batches(&batches)?,
&"json" => {
let bytes = encoding::json::record_batches_to_bytes(&batches)?;
bytes_to_stdout(&bytes)?;
}
"csv" => {
&"csv" => {
let bytes = encoding::csv::record_batches_to_bytes(&batches)?;
bytes_to_stdout(&bytes)?;
}
"parquet" => {
&"parquet" => {
let bytes = encoding::parquet::record_batches_to_bytes(&batches)?;
bytes_to_stdout(&bytes)?;
}
"arrow" => {
&"arrow" => {
let bytes = encoding::arrow::record_batches_to_file_bytes(&batches)?;
bytes_to_stdout(&bytes)?;
}
"arrows" => {
&"arrows" => {
let bytes = encoding::arrow::record_batches_to_stream_bytes(&batches)?;
bytes_to_stdout(&bytes)?;
}
@ -175,18 +174,16 @@ async fn main() -> anyhow::Result<()> {
.help("SQL query to execute")
.index(1)
.required(true)
.takes_value(true)
.number_of_values(1),
.num_args(1),
clap::Arg::new("output")
.help("Query output format")
.long("output")
.short('o')
.required(false)
.takes_value(true)
.number_of_values(1)
.num_args(1)
.default_value("table")
// TODO: add yaml
.possible_values(["table", "json", "csv", "parquet", "arrow", "arrows"]),
.value_parser(["table", "json", "csv", "parquet", "arrow", "arrows"]),
table_arg(),
]),
)

View File

@ -44,7 +44,7 @@ calamine = "0.19.1"
tokio = { version = "1", features = ["rt-multi-thread"] }
futures = "0.3"
hyper-tls = { version = "0.5.0", default-features = false, optional = true }
hyper-rustls = { version = "0.23.2", default-features = false, optional = true }
hyper-rustls = { version = "0.24.1", default-features = false, optional = true }
tokio-postgres = { version = "0.7.8", optional = true }
[dependencies.deltalake]

View File

@ -36,7 +36,7 @@ serde_json = "1"
serde_derive = "1"
serde_yaml = "0.8"
toml = "0.7"
clap = { version = "3", features = ["color"] }
clap = { version = "4", features = ["color"] }
thiserror = "1"
snafu = "0"

View File

@ -48,80 +48,80 @@ pub struct Config {
pub flight_sql_config: Option<FlightSqlConfig>,
}
fn table_arg() -> clap::Arg<'static> {
fn table_arg() -> clap::Arg {
clap::Arg::new("table")
.help("Table sources to load. Table option can be provided as optional setting as part of the table URI, for example: `blogs=s3://bucket/key,format=delta`. Set table uri to `stdin` if you want to consume table data from stdin as part of a UNIX pipe. If no table_name is provided, a table name will be derived from the filename in URI.")
.takes_value(true)
.num_args(1)
.required(false)
.number_of_values(1)
.multiple_occurrences(true)
.action(clap::ArgAction::Append)
.value_name("[table_name=]uri[,option_key=option_value]")
.long("table")
.short('t')
}
fn address_http_arg() -> clap::Arg<'static> {
fn address_http_arg() -> clap::Arg {
clap::Arg::new("addr-http")
.help("HTTP endpoint bind address")
.required(false)
.takes_value(true)
.num_args(1)
.value_name("IP:PORT")
.long("addr-http")
.short('a')
}
fn address_postgres_arg() -> clap::Arg<'static> {
fn address_postgres_arg() -> clap::Arg {
clap::Arg::new("addr-postgres")
.help("Postgres endpoint bind address")
.required(false)
.takes_value(true)
.num_args(1)
.value_name("IP:PORT")
.long("addr-postgres")
.short('p')
}
fn address_flight_sql_arg() -> clap::Arg<'static> {
fn address_flight_sql_arg() -> clap::Arg {
clap::Arg::new("addr-flight-sql")
.help("FlightSQL endpoint bind address")
.required(false)
.takes_value(true)
.num_args(1)
.value_name("IP:PORT")
.long("addr-flight-sql")
}
fn read_only_arg() -> clap::Arg<'static> {
fn read_only_arg() -> clap::Arg {
clap::Arg::new("disable-read-only")
.help("Start roapi in read write mode")
.required(false)
.takes_value(false)
.num_args(0)
.long("disable-read-only")
.short('d')
}
fn reload_interval_arg() -> clap::Arg<'static> {
fn reload_interval_arg() -> clap::Arg {
clap::Arg::new("reload-interval")
.help("maximum age in seconds before triggering rescan and reload of the tables")
.required(false)
.takes_value(true)
.num_args(1)
.long("reload-interval")
.short('r')
}
fn response_format_arg() -> clap::Arg<'static> {
fn response_format_arg() -> clap::Arg {
clap::Arg::new("response-format")
.help("change response serialization: Json (default), Csv, ArrowFile, ArrowStream, Parquet")
.required(false)
.takes_value(true)
.num_args(1)
.value_name("ResponseFormat")
.long("response-format")
.short('f')
}
fn config_arg() -> clap::Arg<'static> {
fn config_arg() -> clap::Arg {
clap::Arg::new("config")
.help("config file path")
.required(false)
.takes_value(true)
.num_args(1)
.long("config")
.short('c')
}
@ -146,7 +146,7 @@ pub fn get_configuration() -> Result<Config, Whatever> {
])
.get_matches();
let mut config: Config = match matches.value_of("config") {
let mut config: Config = match matches.get_one::<String>("config") {
None => Config::default(),
Some(config_path) => {
let config_content = whatever!(
@ -169,7 +169,7 @@ pub fn get_configuration() -> Result<Config, Whatever> {
}
};
if let Some(tables) = matches.values_of("table") {
if let Some(tables) = matches.get_many::<String>("table") {
for v in tables {
config.tables.push(whatever!(
parse_table_uri_arg(v),
@ -178,32 +178,30 @@ pub fn get_configuration() -> Result<Config, Whatever> {
}
}
if let Some(addr) = matches.value_of("addr-http") {
config.addr.http = Some(addr.to_string());
if let Some(addr) = matches.get_one::<String>("addr-http") {
config.addr.http = Some(addr.to_owned());
}
if let Some(addr) = matches.value_of("addr-postgres") {
config.addr.postgres = Some(addr.to_string());
if let Some(addr) = matches.get_one::<String>("addr-postgres") {
config.addr.postgres = Some(addr.to_owned());
}
if let Some(addr) = matches.value_of("addr-flight-sql") {
config.addr.flight_sql = Some(addr.to_string());
if let Some(addr) = matches.get_one::<String>("addr-flight-sql") {
config.addr.flight_sql = Some(addr.to_owned());
}
if matches.is_present("disable-read-only") {
if matches.contains_id("disable-read-only") {
config.disable_read_only = true;
}
if let Some(reload_interval) = matches.value_of("reload-interval") {
if let Some(reload_interval) = matches.get_one::<u64>("reload-interval") {
if !config.disable_read_only {
whatever!("Table reload not supported in read-only mode. Try specify the --disable-read-only option.");
}
config.reload_interval = Some(Duration::from_secs(
reload_interval.to_string().parse().unwrap(),
));
config.reload_interval = Some(Duration::from_secs(reload_interval.to_owned()));
}
if let Some(response_format) = matches.value_of("response-format") {
if let Some(response_format) = matches.get_one::<String>("response-format") {
config.response_format = whatever!(
serde_yaml::from_str(response_format),
"Failed parse response-format",