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'"
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    /// Read from file instead of stdin
19    #[arg(short, long)]
20    pub file: Option<String>,
21
22    /// Output result as JSON
23    #[arg(long)]
24    pub json: bool,
25
26    /// Output without trailing newline
27    #[arg(long)]
28    pub raw: bool,
29
30    /// Only output first result
31    #[arg(short = '1', long)]
32    pub first: bool,
33
34    /// Output array elements one per line
35    #[arg(long)]
36    pub lines: bool,
37
38    /// Default value if selector doesn't match
39    #[arg(short, long)]
40    pub default: Option<String>,
41
42    /// Suppress error messages
43    #[arg(short, long)]
44    pub quiet: bool,
45
46    /// Check if selector matches (exit code only: 0=found, 1=not found)
47    #[arg(short, long)]
48    pub exists: bool,
49
50    /// Output count of matches
51    #[arg(short, long)]
52    pub count: bool,
53}
54
55#[derive(clap::ValueEnum, Clone, Debug, PartialEq)]
56pub enum InputFormat {
57    Auto,
58    Json,
59    Yaml,
60    Toml,
61    Env,
62    Headers,
63    Logfmt,
64    Csv,
65    Text,
66}