Skip to content

Commit 4bc2508

Browse files
Move host arg
1 parent 269bb09 commit 4bc2508

6 files changed

Lines changed: 55 additions & 14 deletions

File tree

src/args.rs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,28 +92,25 @@ pub struct DftArgs {
9292
#[clap(short = 'n', help = "Set the number of benchmark iterations to run")]
9393
pub benchmark_iterations: Option<usize>,
9494

95-
#[cfg(any(feature = "flightsql", feature = "http"))]
96-
#[clap(
97-
long,
98-
global = true,
99-
help = "Set the host and port to be used for server"
100-
)]
101-
pub host: Option<String>,
102-
10395
#[clap(
10496
long,
10597
short,
10698
help = "Path to save output to. Type is inferred from file suffix"
10799
)]
108100
pub output: Option<PathBuf>,
109101

102+
#[cfg(any(feature = "flightsql", feature = "http"))]
110103
#[command(subcommand)]
111104
pub command: Option<Command>,
112105
}
113106

114107
impl DftArgs {
115108
pub fn config_path(&self) -> PathBuf {
116-
if let Some(Command::ServeFlightSql { config: Some(cfg) }) = &self.command {
109+
#[cfg(any(feature = "flightsql", feature = "http"))]
110+
if let Some(Command::ServeFlightSql {
111+
config: Some(cfg), ..
112+
}) = &self.command
113+
{
117114
return Path::new(cfg).to_path_buf();
118115
}
119116
if let Some(config) = self.config.as_ref() {
@@ -132,12 +129,24 @@ pub enum Command {
132129
ServeHttp {
133130
#[clap(short, long)]
134131
config: Option<String>,
132+
#[clap(
133+
long,
134+
global = true,
135+
help = "Set the host and port to be used for server"
136+
)]
137+
host: Option<String>,
135138
},
136139
/// Start a FlightSQL server
137140
#[command(name = "serve-flightsql")]
138141
ServeFlightSql {
139142
#[clap(short, long)]
140143
config: Option<String>,
144+
#[clap(
145+
long,
146+
global = true,
147+
help = "Set the host and port to be used for server"
148+
)]
149+
host: Option<String>,
141150
},
142151
}
143152

src/cli/mod.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
// under the License.
1717
//! [`CliApp`]: Command Line User Interface
1818
19+
use crate::args::Command;
1920
use crate::config::AppConfig;
2021
use crate::{args::DftArgs, execution::AppExecution};
2122
use color_eyre::eyre::eyre;
@@ -613,7 +614,15 @@ pub async fn try_run(cli: DftArgs, config: AppConfig) -> Result<()> {
613614
auth,
614615
);
615616
let flightsql_ctx = FlightSQLContext::new(flightsql_cfg);
616-
flightsql_ctx.create_client(cli.host.clone()).await?;
617+
let url = if let Some(cmd) = cli.command.clone() {
618+
match cmd {
619+
Command::ServeFlightSql { host, .. } => host,
620+
Command::ServeHttp { host, .. } => host,
621+
}
622+
} else {
623+
None
624+
};
625+
flightsql_ctx.create_client(url).await?;
617626
app_execution.with_flightsql_ctx(flightsql_ctx);
618627
}
619628
}

src/server/flightsql/mod.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,18 @@ pub async fn try_run(cli: DftArgs, config: AppConfig) -> Result<()> {
188188
execution_ctx.execute_ddl().await;
189189
}
190190
let app_execution = AppExecution::new(execution_ctx);
191+
let url = if let Some(cmd) = cli.command.clone() {
192+
match cmd {
193+
crate::args::Command::ServeFlightSql { host, .. } => host,
194+
crate::args::Command::ServeHttp { host, .. } => host,
195+
}
196+
} else {
197+
None
198+
};
191199
let app = FlightSqlApp::try_new(
192200
app_execution,
193201
&config,
194-
&cli.host.unwrap_or(DEFAULT_SERVER_ADDRESS.to_string()),
202+
&url.unwrap_or(DEFAULT_SERVER_ADDRESS.to_string()),
195203
&config.flightsql_server.server_metrics_port,
196204
)
197205
.await?;

src/server/http/mod.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,18 @@ pub async fn try_run(cli: DftArgs, config: AppConfig) -> Result<()> {
153153
}
154154
}
155155
debug!("Created AppExecution: {app_execution:?}");
156+
let url = if let Some(cmd) = cli.command.clone() {
157+
match cmd {
158+
crate::args::Command::ServeFlightSql { host, .. } => host,
159+
crate::args::Command::ServeHttp { host, .. } => host,
160+
}
161+
} else {
162+
None
163+
};
156164
let app = HttpApp::try_new(
157165
app_execution,
158166
config.clone(),
159-
&cli.host.unwrap_or(DEFAULT_SERVER_ADDRESS.to_string()),
167+
&url.unwrap_or(DEFAULT_SERVER_ADDRESS.to_string()),
160168
&config.http_server.server_metrics_port,
161169
)
162170
.await?;

src/server/http/router.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,6 @@ mod test {
286286
config::ExecutionConfig, extensions::DftSessionStateBuilder, local::ExecutionContext,
287287
};
288288
use http::{Request, StatusCode};
289-
use http_body_util::BodyExt;
290289

291290
use crate::{
292291
config::HttpServerConfig, execution::AppExecution, server::http::router::create_router,

src/tui/handlers/mod.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use log::{error, info, trace};
2424
use ratatui::crossterm::event::{self, KeyCode, KeyEvent};
2525
use tui_logger::TuiWidgetEvent;
2626

27+
use crate::args::Command;
2728
#[cfg(feature = "flightsql")]
2829
use crate::tui::state::tabs::flightsql::FlightSQLConnectionStatus;
2930
use crate::tui::state::tabs::history::Context;
@@ -245,7 +246,14 @@ pub fn app_event_handler(app: &mut App, event: AppEvent) -> Result<()> {
245246
AppEvent::FlightSQLEstablishConnection => {
246247
let execution = Arc::clone(&app.execution);
247248
let _event_tx = app.event_tx.clone();
248-
let cli_url = app.args.host.clone();
249+
let cli_url = if let Some(cmd) = app.args.command.clone() {
250+
match cmd {
251+
Command::ServeFlightSql { host, .. } => host,
252+
Command::ServeHttp { host, .. } => host,
253+
}
254+
} else {
255+
None
256+
};
249257
tokio::spawn(async move {
250258
if let Err(e) = execution.create_flightsql_client(cli_url).await {
251259
error!("Error creating FlightSQL client: {:?}", e);

0 commit comments

Comments
 (0)