Skip to main content

pick/
cli.rs

1use clap::Parser;
2
3#[derive(Parser, Debug)]
4#[command(
5    name = "pick",
6    version,
7    about = "Extract values from anything",
8    long_about = "A universal extraction tool for JSON, YAML, TOML, .env, HTTP headers, logfmt, CSV, and more.\n\nExamples:\n  curl -s api.com/user | pick profile.email\n  cat .env | pick DATABASE_URL\n  cat server.log | pick request_id\n  docker inspect ctr | pick '[0].State.Status'\n  cat data.json | pick 'items[*] | select(.price > 100) | name'\n  cat config.yaml | pick 'set(.version, \"2.0\")'"
9)]
10pub struct Cli {
11    /// Selector expression (e.g., foo.bar, items[0].name, [*].id)
12    pub selector: Option<String>,
13
14    /// Input format override
15    #[arg(short, long, value_enum, default_value = "auto")]
16    pub input: InputFormat,
17
18    /// Output format override (default: auto-match input)
19    #[arg(short, long, value_enum, default_value = "auto")]
20    pub output: OutputFormat,
21
22    /// Read from file instead of stdin
23    #[arg(short, long)]
24    pub file: Option<String>,
25
26    /// Output result as JSON
27    #[arg(long)]
28    pub json: bool,
29
30    /// Output without trailing newline
31    #[arg(long)]
32    pub raw: bool,
33
34    /// Only output first result
35    #[arg(short = '1', long)]
36    pub first: bool,
37
38    /// Output array elements one per line
39    #[arg(long)]
40    pub lines: bool,
41
42    /// Default value if selector doesn't match
43    #[arg(short, long)]
44    pub default: Option<String>,
45
46    /// Suppress error messages
47    #[arg(short, long)]
48    pub quiet: bool,
49
50    /// Check if selector matches (exit code only: 0=found, 1=not found)
51    #[arg(short, long)]
52    pub exists: bool,
53
54    /// Output count of matches
55    #[arg(short, long)]
56    pub count: bool,
57
58    /// Stream mode: process JSONL input line-by-line
59    #[arg(long)]
60    pub stream: bool,
61}
62
63#[derive(clap::ValueEnum, Clone, Debug, PartialEq)]
64pub enum InputFormat {
65    Auto,
66    Json,
67    Yaml,
68    Toml,
69    Env,
70    Headers,
71    Logfmt,
72    Csv,
73    Text,
74}
75
76#[derive(clap::ValueEnum, Clone, Debug, PartialEq)]
77pub enum OutputFormat {
78    Auto,
79    Json,
80    Yaml,
81    Toml,
82}