You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.3 KiB
Rust
52 lines
1.3 KiB
Rust
/* TODO:
|
|
* . add clap for CLI flags
|
|
* . read input as column field1920s
|
|
* . test splitting input into fields
|
|
* . execute arbitrary shell commands to manipulate input
|
|
* . dynamically generate field parameters ?
|
|
*/
|
|
|
|
use clap::Parser;
|
|
use colmap::parsing::DEFAULT_SEP_PATTERN;
|
|
|
|
#[derive(Parser)]
|
|
/// colmap - map commands to columns of text input
|
|
///
|
|
/// The colmap command reads text from stdin as columns. Each column is then passed to a command
|
|
/// specified by the user. Commands are mapped to specific columns using positional arguments.
|
|
///
|
|
/// The first command is applied to the first column, the second command to the second column, etc.
|
|
#[command(name="colmap")]
|
|
#[command(author="blob42")]
|
|
#[command(version="0.1")]
|
|
struct Cli {
|
|
/// separator character used to split text into columns
|
|
#[arg(default_value_t=DEFAULT_SEP_PATTERN.to_owned())]
|
|
#[arg(short)]
|
|
delimiter: String,
|
|
|
|
#[arg(short, long, action = clap::ArgAction::Count)]
|
|
debug: u8,
|
|
|
|
/// execute CMD each column of input. 0 < N_CMD < NB_COLUMNS
|
|
commands: Vec<String>
|
|
}
|
|
|
|
fn main() {
|
|
let cli = Cli::parse();
|
|
|
|
// if let None = cli.f1.as_deref() {
|
|
// eprintln!("no field --fX to operate on");
|
|
// process::exit(1);
|
|
// }
|
|
|
|
if cli.debug > 0 {
|
|
println!("{:?}", cli.delimiter);
|
|
}
|
|
|
|
for c in cli.commands {
|
|
println!("- {}", c);
|
|
}
|
|
}
|
|
|