use anyhow::Result;
use clap::Parser;
#[derive(Parser, Debug)]
#[clap(
author,
version,
about = "SQL-based processor for delimiter-separated files",
long_about = "sqawk runs SQL against delimiter-separated files (CSV, TSV, etc.).\n\n\
Each input file is loaded as an in-memory table named after the file, \
or after the name given as [table_name=]file_path. Statements run in \
the order given, and each one sees the effects of those before it.\n\n\
Input files are never modified unless --write is given, and then only \
the tables an INSERT, UPDATE or DELETE actually changed."
)]
pub struct SqawkArgs {
#[clap(
short,
long,
required_unless_present = "interactive",
help = "SQL statement to execute"
)]
pub sql: Vec<String>,
#[clap(short, long, help = "Start in interactive mode")]
pub interactive: bool,
#[clap(
required = true,
help = "Input files to process as [table_name=]file_path ('-' for stdin)"
)]
pub files: Vec<String>,
#[clap(
long,
help = "Define column names for tables as table_name:col1,col2,col3,..."
)]
pub tabledef: Vec<String>,
#[clap(short = 'F', help = "Field separator character")]
pub field_separator: Option<String>,
#[clap(short, long, help = "Enable verbose output")]
pub verbose: bool,
#[clap(short = 'w', long, help = "Write changes back to input files")]
pub write: bool,
}
pub fn parse_args() -> Result<SqawkArgs> {
Ok(SqawkArgs::parse())
}