Skip to content

Commit 42fbe78

Browse files
Improve cli parsing (#284)
1 parent b0b67f3 commit 42fbe78

4 files changed

Lines changed: 22 additions & 10 deletions

File tree

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ jobs:
270270
uses: ./.github/actions/setup-rust
271271
- name: Start FlightSQL Server
272272
run: |
273-
cargo r --features=flightsql -- --serve --config data/configs/flightsql_basic.toml &
273+
cargo r --features=flightsql -- serve-flight-sql --config data/configs/flightsql_basic.toml &
274274
- name: Run auth tests
275275
run: |
276276
cargo t --features=flightsql extension_cases::auth_basic
@@ -298,7 +298,7 @@ jobs:
298298
uses: ./.github/actions/setup-rust
299299
- name: Start FlightSQL Server
300300
run: |
301-
cargo r --features=flightsql -- --serve --config data/configs/flightsql_bearer.toml &
301+
cargo r --features=flightsql -- serve-flight-sql --config data/configs/flightsql_bearer.toml &
302302
- name: Run auth tests
303303
run: |
304304
cargo t --features=flightsql extension_cases::auth_bearer

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ This feature is still in it's early stages and is expected to evolve. Once it h
156156

157157
## `dft` FlightSQL Server
158158

159-
The `dft` FlightSQL server (feature flag `flightsql`) is a Flight service that can be used to execute SQL queries against DataFusion. The server is started by running `dft --serve` and can optionally run your configured DDL with the `--run-ddl` parameter. Prometheus metrics are automatically exported as part of this.
159+
The `dft` FlightSQL server (feature flag `flightsql`) is a Flight service that can be used to execute SQL queries against DataFusion. The server is started by running `dft serve-flight-sql` and can optionally run your configured DDL with the `--run-ddl` parameter. Prometheus metrics are automatically exported as part of this.
160160

161161
This feature is experimental and does not currently implement all FlightSQL endpoints. Endpoints will be added in tandem with adding more features to the FlightSQL clients within the TUI and CLI.
162162

src/args.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
//! Command line argument parsing: [`DftArgs`]
1919
2020
use crate::config::get_data_dir;
21-
use clap::Parser;
21+
use clap::{Parser, Subcommand};
2222
use std::path::{Path, PathBuf};
2323

2424
const LONG_ABOUT: &str = "
@@ -67,10 +67,6 @@ pub struct DftArgs {
6767
#[clap(long, short, help = "Only show how long the query took to run")]
6868
pub time: bool,
6969

70-
#[cfg(feature = "flightsql")]
71-
#[clap(long, help = "Start a FlightSQL server")]
72-
pub serve: bool,
73-
7470
#[clap(long, short, help = "Benchmark the provided query")]
7571
pub bench: bool,
7672

@@ -102,10 +98,16 @@ pub struct DftArgs {
10298
help = "Path to save output to. Type is inferred from file suffix"
10399
)]
104100
pub output: Option<PathBuf>,
101+
102+
#[command(subcommand)]
103+
pub command: Option<Command>,
105104
}
106105

107106
impl DftArgs {
108107
pub fn config_path(&self) -> PathBuf {
108+
if let Some(Command::ServeFlightSql { config: Some(cfg) }) = &self.command {
109+
return Path::new(cfg).to_path_buf();
110+
}
109111
if let Some(config) = self.config.as_ref() {
110112
Path::new(config).to_path_buf()
111113
} else {
@@ -116,6 +118,15 @@ impl DftArgs {
116118
}
117119
}
118120

121+
#[derive(Clone, Debug, Subcommand)]
122+
pub enum Command {
123+
/// Start a FlightSQL server
124+
ServeFlightSql {
125+
#[clap(short, long)]
126+
config: Option<String>,
127+
},
128+
}
129+
119130
fn parse_valid_file(file: &str) -> std::result::Result<PathBuf, String> {
120131
let path = PathBuf::from(file);
121132
if !path.exists() {

src/main.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use clap::Parser;
1919
use color_eyre::Result;
2020
use datafusion_app::local::ExecutionContext;
2121
use datafusion_app::{config::merge_configs, extensions::DftSessionStateBuilder};
22+
use datafusion_dft::args::Command;
2223
use datafusion_dft::{
2324
args::DftArgs,
2425
cli::CliApp,
@@ -52,7 +53,7 @@ fn main() -> Result<()> {
5253

5354
fn should_init_env_logger(cli: &DftArgs) -> bool {
5455
#[cfg(feature = "flightsql")]
55-
if cli.serve {
56+
if let Some(Command::ServeFlightSql { .. }) = cli.command {
5657
return true;
5758
}
5859
if !cli.files.is_empty() || !cli.commands.is_empty() {
@@ -67,7 +68,7 @@ async fn app_entry_point(cli: DftArgs) -> Result<()> {
6768
}
6869
let state = state::initialize(cli.config_path());
6970
#[cfg(feature = "flightsql")]
70-
if cli.serve {
71+
if let Some(Command::ServeFlightSql { .. }) = cli.command {
7172
let merged_exec_config = merge_configs(
7273
state.config.shared.clone(),
7374
state.config.flightsql_server.execution.clone(),

0 commit comments

Comments
 (0)