Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,31 @@ categories = ["command-line-utilities"]
description = "Replace with description"
documentation = "https://docs.rs/arrow_cli"
repository = "https://github.com/sundy-li/arrow_cli"
edition = "2021"
edition = "2024"
license = "Apache-2.0"
name = "arrow_cli"
version = "0.1.3"

version = "0.2.0"


[dependencies]
shlex = "1.1.0"
atty = "0.2"
rustyline = "11.0.0"
arrow-cast = { version = "51", features = ["prettyprint"] }
arrow-flight = { version = "51", features = ["flight-sql-experimental"] }
arrow = { version = "51", features = ["ipc_compression"] }
rustyline = "15"
arrow-cast = { version = "55", features = ["prettyprint"] }
arrow-flight = { version = "55", features = ["flight-sql-experimental"] }
arrow = { version = "55", features = ["ipc_compression"] }
futures = { version = "0.3", default-features = false, features = ["alloc"] }
tokio = { version = "1.26", features = [
tokio = { version = "1", features = [
"macros",
"rt",
"rt-multi-thread",
"sync",
"parking_lot",
] }

tonic = { version = "0.11", default-features = false, features = [
tonic = { version = "0.12", default-features = false, features = [
"transport",
"codegen",
"tls",
"prost",
] }
clap = { version = "4.1.0", features = ["derive"] }
clap = { version = "4.5", features = ["derive"] }
25 changes: 14 additions & 11 deletions src/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@

use std::borrow::Cow;

use rustyline::Context;
use rustyline::Helper;
use rustyline::Result;
use rustyline::completion::Completer;
use rustyline::completion::FilenameCompleter;
use rustyline::completion::Pair;
use rustyline::error::ReadlineError;
use rustyline::highlight::Highlighter;
use rustyline::highlight::{CmdKind, Highlighter};
use rustyline::hint::Hinter;
use rustyline::validate::ValidationContext;
use rustyline::validate::ValidationResult;
use rustyline::validate::Validator;
use rustyline::Context;
use rustyline::Helper;
use rustyline::Result;

pub struct CliHelper {
completer: FilenameCompleter,
Expand Down Expand Up @@ -78,25 +78,25 @@ impl Highlighter for CliHelper {
&'s self,
prompt: &'p str,
default: bool,
) -> std::borrow::Cow<'b, str> {
) -> Cow<'b, str> {
let _ = default;
std::borrow::Cow::Borrowed(prompt)
Cow::Borrowed(prompt)
}

fn highlight_hint<'h>(&self, hint: &'h str) -> std::borrow::Cow<'h, str> {
std::borrow::Cow::Owned("\x1b[1m".to_owned() + hint + "\x1b[m")
Cow::Owned("\x1b[1m".to_owned() + hint + "\x1b[m")
}

fn highlight_candidate<'c>(
&self,
candidate: &'c str, // FIXME should be Completer::Candidate
completion: rustyline::CompletionType,
) -> std::borrow::Cow<'c, str> {
) -> Cow<'c, str> {
let _ = completion;
std::borrow::Cow::Borrowed(candidate)
Cow::Borrowed(candidate)
}

fn highlight_char(&self, line: &str, _pos: usize) -> bool {
fn highlight_char(&self, line: &str, _pos: usize, _kind: CmdKind) -> bool {
!line.is_empty()
}
}
Expand Down Expand Up @@ -187,7 +187,10 @@ static KEYWORDS: &str = include_str!("keywords.txt");

impl KeyWordCompleter {
fn complete(s: &str, pos: usize) -> (usize, Vec<Pair>) {
let hint = s.split(|p: char| p.is_whitespace()).last().unwrap_or(s);
let hint = s
.split(|p: char| p.is_whitespace())
.next_back()
.unwrap_or(s);
let res: (usize, Vec<Pair>) = (
pos - hint.len(),
KEYWORDS
Expand Down
10 changes: 6 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ struct Args {

#[clap(long, help = "Print help information")]
help: bool,

#[clap(long, default_value = "180", help = "Request timeout in seconds")]
timeout: u64,
}

#[tokio::main]
Expand All @@ -61,18 +64,17 @@ pub async fn main() -> Result<(), ArrowError> {
}

fn print_usage() {
let msg =
r#"Usage: arrow_cli <--user <USER>|--password <PASSWORD>|--host <HOST>|--port <PORT>>"#;
let msg = r#"Usage: arrow_cli <--user <USER>|--password <PASSWORD>|--host <HOST>|--port <PORT>|--timeout <TIME>>"#;
println!("{}", msg);
}

fn endpoint(args: &Args, addr: String) -> Result<Endpoint, ArrowError> {
let mut endpoint = Endpoint::new(addr)
.map_err(|_| ArrowError::IpcError("Cannot create endpoint".to_string()))?
.connect_timeout(Duration::from_secs(20))
.timeout(Duration::from_secs(180))
.timeout(Duration::from_secs(args.timeout))
.tcp_nodelay(true) // Disable Nagle's Algorithm since we don't want packets to wait
.tcp_keepalive(Option::Some(Duration::from_secs(3600)))
.tcp_keepalive(Some(Duration::from_secs(3600)))
.http2_keep_alive_interval(Duration::from_secs(300))
.keep_alive_timeout(Duration::from_secs(20))
.keep_alive_while_idle(true);
Expand Down
2 changes: 1 addition & 1 deletion src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use arrow::record_batch::RecordBatch;
use arrow_cast::pretty::pretty_format_batches;
use arrow_flight::sql::client::FlightSqlServiceClient;
use futures::TryStreamExt;
use rustyline::Editor;
use rustyline::error::ReadlineError;
use rustyline::history::DefaultHistory;
use rustyline::Editor;
use std::io::BufRead;
use tokio::time::Instant;
use tonic::transport::{Channel, Endpoint};
Expand Down