1use std::path::PathBuf;
2
3use clap::Parser;
4
5use crate::Error;
6
7#[derive(Debug, Parser)]
12#[command(name = "hawk")]
13#[command(version = "0.1.0")]
14#[command(about = "Modern data analysis tool for structured data")]
15#[command(long_about = "
16hawk is a command-line data analysis tool that brings pandas-like functionality
17to your terminal. It supports JSON, YAML, and CSV formats with automatic detection,
18powerful filtering, grouping, and aggregation capabilities.
19
20EXAMPLES:
21 # Basic field access
22 hawk '.users[0].name' data.json
23 hawk '.users.name' data.csv
24
25 # Filtering and aggregation
26 hawk '.users[] | select(.age > 30)' data.yaml
27 hawk '.sales | group_by(.region) | avg(.amount)' sales.csv
28
29 # Data exploration
30 hawk '. | info' data.json
31 hawk '.users | count' data.csv
32
33SUPPORTED FORMATS:
34 JSON, YAML, CSV (automatically detected)
35
36QUERY SYNTAX:
37 .field - Access field
38 .array[0] - Access array element
39 .array[] - Access all array elements
40 . | select(.field > 10) - Filter data
41 . | group_by(.category) - Group data
42 . | count/sum/avg/min/max - Aggregate functions
43")]
44pub struct Args {
45 pub query: String,
52
53 pub path: Option<PathBuf>,
58
59 #[arg(long, default_value = "auto")]
66 #[arg(value_parser = ["auto", "table", "json", "list"])]
67 pub format: String,
68}
69
70#[derive(Debug, Clone)]
71pub enum OutputFormat {
72 Auto,
73 Json,
74 Table,
75 List,
76 }
78
79impl std::str::FromStr for OutputFormat {
80 type Err = Error;
81
82 fn from_str(s: &str) -> Result<Self, Self::Err> {
83 match s.to_lowercase().as_str() {
84 "auto" => Ok(OutputFormat::Auto),
85 "json" => Ok(OutputFormat::Json),
86 "table" => Ok(OutputFormat::Table),
87 "list" => Ok(OutputFormat::List),
88 _ => Err(Error::InvalidFormat(format!(
90 "Invalid format: {}. Valid options: auto, json, table, list",
91 s
92 ))),
93 }
94 }
95}