1use crate::config::{Config, GeometryMode};
2use clap::{Args, Parser, Subcommand};
3
4#[derive(Parser, Debug)]
6#[clap(version, about)]
7pub struct Cli {
8 #[clap(subcommand)]
9 pub commands: Commands,
10}
11
12impl Cli {
13 pub fn new() -> Commands {
14 Self::parse().commands
15 }
16}
17
18#[derive(Subcommand, Debug)]
19pub enum Commands {
20 #[clap(aliases = &["q"])]
22 Query(QueryArgs),
23 #[clap(aliases = &["e", "config", "init"])]
26 Edit,
27}
28
29#[derive(Args, Debug)]
30pub struct QueryArgs {
31 #[clap(value_parser, long)]
33 pub api_key: Option<String>,
34 #[clap(value_parser, long)]
36 pub mode: Option<GeometryMode>,
37 #[clap(value_parser, long)]
39 pub minutely: Option<bool>,
40 #[clap(value_parser, long)]
42 pub hourly: Option<bool>,
43 #[clap(value_parser, long)]
45 pub daily: Option<bool>,
46}
47
48impl QueryArgs {
49 pub fn update_config(self, config: &mut Config) {
50 if let Some(key) = self.api_key {
51 log::warn!("Api key should be set in config file");
52 config.api_key = key;
53 }
54 if let Some(mode) = self.mode {
55 log::warn!("Geometry mode should be set in config file");
56 config.geometry_mode = mode;
57 }
58 if let Some(b) = self.minutely {
59 config.minutely = b;
60 }
61 if let Some(b) = self.hourly {
62 config.hourly = b;
63 }
64 if let Some(b) = self.daily {
65 config.daily = b;
66 }
67 }
68}