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