axe_cli/
cli.rs

1use std::path::PathBuf;
2
3use clap::{arg, command, Args};
4
5use clap::Parser;
6
7#[derive(Parser)]
8#[command(version, about, long_about = Some("Run command for each entry of arguments"))]
9pub struct Cli {
10    #[arg(default_value = "echo")]
11    pub cmd: String,
12    /// Arguments templates that will be resolved and passed to cmd.
13    /// Allowed values:
14    /// - static text
15    /// - {} - all input arguments
16    /// - {<sep>} - all input arguments, each splittded by <sep> and all parts of split are taken
17    /// - {<sep>y} - all input arguments, each splittded by <sep> and y-th part of split is taken
18    /// - {x} - x-th argument
19    /// - {x<sep>} - x-th argument splittded by <sep> and all parts of split are taken
20    /// - {x<sep>y} - x-th argument splittded by <sep> and y-th part of split is taken.
21    #[arg(verbatim_doc_comment)]
22    pub args_templates: Vec<String>,
23    /// Separator between args. Each entry line will be splitted by this separator
24    #[arg(short, long, default_value = " ")]
25    pub args_separator: String,
26    /// Print command with resolved args instead of running it
27    #[arg(short, long)]
28    pub debug: bool,
29    /// Reads arguments from file instead of standard input
30    #[arg(short = 'f', long, value_name = "FILE")]
31    pub args_file: Option<PathBuf>,
32    #[command(flatten)]
33    pub entries: EntriesOptions,
34}
35
36#[derive(Args)]
37#[group(required = false, multiple = false)]
38pub struct EntriesOptions {
39    /// Separator between entries. Each entry will be splitted by args_separator to produce cmd args
40    #[arg(short, long, default_value = "\n")]
41    pub entries_separator: String,
42
43    /// Load all input as single entry
44    #[arg(short = '0', long = "single-entry", default_value_t = false)]
45    pub single_entry: bool,
46
47    /// Splits input into entries of specified size
48    #[arg(short = 's', long = "entries-size", default_value_t = 0)]
49    pub entry_size: usize,
50}