Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
33 changes: 3 additions & 30 deletions influxdb3/src/commands/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ pub(crate) enum Error {
#[error(transparent)]
Client(#[from] influxdb3_client::Error),

#[error(transparent)]
Query(#[from] QueryError),

#[error("invlid UTF8 received from server: {0}")]
Utf8(#[from] Utf8Error),

Expand All @@ -42,7 +39,7 @@ pub(crate) enum Error {
pub(crate) type Result<T> = std::result::Result<T, Error>;

#[derive(Debug, Parser)]
#[clap(visible_alias = "q", trailing_var_arg = true)]
#[clap(visible_alias = "q")]
pub struct Config {
/// Common InfluxDB 3 Core config
#[clap(flatten)]
Expand Down Expand Up @@ -73,7 +70,7 @@ pub struct Config {
file_path: Option<String>,

/// The query string to execute
query: Option<Vec<String>>,
query: Option<String>,
}

#[derive(Debug, ValueEnum, Clone)]
Expand All @@ -94,7 +91,7 @@ pub(crate) async fn command(config: Config) -> Result<()> {
}

let query = if let Some(query) = config.query {
parse_query(query)?
query
} else if let Some(file_path) = config.file_path {
fs::read_to_string(file_path)?
} else {
Expand Down Expand Up @@ -145,27 +142,3 @@ pub(crate) async fn command(config: Config) -> Result<()> {

Ok(())
}

#[derive(Debug, thiserror::Error)]
pub(crate) enum QueryError {
#[error("no query provided")]
NoQuery,

#[error(
"ensure that a single query string is provided as the final \
argument, enclosed in quotes"
)]
MoreThanOne,
}

/// Parse the user-inputted query string
fn parse_query(mut input: Vec<String>) -> Result<String> {
if input.is_empty() {
Err(QueryError::NoQuery)?
}
if input.len() > 1 {
Err(QueryError::MoreThanOne)?
} else {
Ok(input.remove(0))
}
}
2 changes: 1 addition & 1 deletion influxdb3/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use trogging::{
};

pub mod commands {
pub(crate) mod common;
pub mod common;
pub mod create;
pub mod delete;
pub mod disable;
Expand Down
Loading