|
| 1 | +// This file is part of the uutils awk package. |
| 2 | +// |
| 3 | +// For the full copyright and license information, please view the LICENSE |
| 4 | +// files that was distributed with this source code. |
| 5 | + |
| 6 | +use std::{ffi::OsString, path::PathBuf}; |
| 7 | + |
| 8 | +use clap::Parser; |
| 9 | + |
| 10 | +#[derive(Parser, Debug)] |
| 11 | +#[clap(version, name = "uutils AWK")] |
| 12 | +#[clap(about = ::std::concat!("uutils awk ", ::std::env!("CARGO_PKG_VERSION")))] |
| 13 | +pub struct Args { |
| 14 | + // POSIX |
| 15 | + pub code: OsString, |
| 16 | + #[arg(short = 'f', long)] |
| 17 | + file: Option<PathBuf>, |
| 18 | + #[arg(short = 'F', long)] |
| 19 | + field_separator: Option<OsString>, |
| 20 | + #[arg(short = 'v', long, value_parser = parse_kv)] |
| 21 | + assign: Vec<(String, String)>, |
| 22 | + #[arg(short = 'b', long)] |
| 23 | + characters_as_bytes: bool, |
| 24 | + #[arg(short = 'c', long)] |
| 25 | + traditional: bool, |
| 26 | + #[arg(short = 'C', long)] |
| 27 | + copyright: bool, |
| 28 | + #[arg(short = 'd', long)] |
| 29 | + dump_variables: Option<PathBuf>, |
| 30 | + #[arg(short = 'D', long)] |
| 31 | + debug: Option<PathBuf>, |
| 32 | + #[arg(short = 'e', long)] |
| 33 | + source: Vec<u8>, |
| 34 | + #[arg(short = 'E', long)] |
| 35 | + exec: Option<PathBuf>, |
| 36 | + #[arg(short = 'g', long)] |
| 37 | + gen_pot: bool, |
| 38 | + #[arg(short = 'i', long)] |
| 39 | + include: Option<PathBuf>, |
| 40 | + #[arg(short = 'I', long)] |
| 41 | + trace: bool, |
| 42 | + #[arg(short = 'l', long)] |
| 43 | + load: Vec<OsString>, |
| 44 | + #[arg(short = 'L', long)] |
| 45 | + lint: Vec<String>, |
| 46 | + #[arg(short = 'M', long)] |
| 47 | + bignum: bool, |
| 48 | + #[arg(short = 'n', long)] |
| 49 | + non_decimal_data: bool, |
| 50 | + #[arg(short = 'N', long)] |
| 51 | + use_lc_numeric: bool, |
| 52 | + #[arg(short = 'o', long)] |
| 53 | + pretty_print: Option<PathBuf>, |
| 54 | + #[arg(short = 'O', long, default_value_t = true)] |
| 55 | + optimize: bool, |
| 56 | + #[arg(short = 's', long = "no-optimize")] |
| 57 | + no_optimize: bool, |
| 58 | + #[arg(short = 'p', long)] |
| 59 | + profile: Option<PathBuf>, |
| 60 | + #[arg(short = 'P', long)] |
| 61 | + posix: bool, |
| 62 | + #[arg(short = 'r', long, default_value_t = true)] |
| 63 | + re_interval: bool, |
| 64 | + #[arg(short = 'S', long)] |
| 65 | + sandbox: bool, |
| 66 | + #[arg(short = 't', long)] |
| 67 | + lint_old: bool, |
| 68 | +} |
| 69 | + |
| 70 | +fn parse_kv(s: &str) -> Result<(String, String), String> { |
| 71 | + let (k, v) = s.split_once('=').ok_or("expected key=value")?; |
| 72 | + Ok((k.to_string(), v.trim_matches(['"', '\'']).to_string())) |
| 73 | +} |
0 commit comments