1use clap::Args;
2
3#[derive(Args, Debug, Clone, Default)]
4pub struct DataArgs {
5 #[arg(
6 long,
7 value_name = "FILE",
8 group = "datasource",
9 requires = "version_selectors",
10 help = "Path to the Excel versions file"
11 )]
12 pub xlsx: Option<String>,
13
14 #[arg(long, value_name = "NAME", help = "Main sheet name in Excel")]
15 pub main_sheet: Option<String>,
16
17 #[arg(
18 long,
19 value_name = "PATH or json string",
20 group = "datasource",
21 requires = "version_selectors",
22 help = "Path to the JSON file or a JSON string containing the postgres configuration (url, query_template, optional data_path for nested extraction)"
23 )]
24 pub postgres: Option<String>,
25
26 #[arg(
27 long,
28 value_name = "PATH or json string",
29 group = "datasource",
30 requires = "version_selectors",
31 help = "HTTP API configuration (url with $VERSION placeholder, optional method [GET/POST], optional body with $VERSION, optional headers, optional data_path)"
32 )]
33 pub http: Option<String>,
34
35 #[arg(
36 long,
37 value_name = "PATH or json string",
38 group = "datasource",
39 requires = "version_selectors",
40 help = "Path to JSON file or JSON string. Format: object with version names as keys, each containing an object with name:value pairs (e.g., {\"VersionName\": {\"key1\": value1, \"key2\": value2}})"
41 )]
42 pub json: Option<String>,
43
44 #[arg(
45 short = 'v',
46 long = "versions",
47 value_name = "NAME[/NAME...]",
48 requires = "datasource",
49 group = "version_selectors",
50 help = "Version columns to use in priority order (separate with '/')"
51 )]
52 pub versions: Option<String>,
53}
54
55impl DataArgs {
56 pub fn get_version_list(&self) -> Vec<String> {
58 let raw = self.versions.as_deref();
59 raw.map(|r| {
60 r.split('/')
61 .map(|name| name.trim())
62 .filter(|name| !name.is_empty())
63 .map(|name| name.to_string())
64 .collect()
65 })
66 .unwrap_or_default()
67 }
68}