atomblocks/
cli.rs

1use argh::{self, FromArgs};
2use std::path::PathBuf;
3
4#[derive(FromArgs, PartialEq, Debug)]
5/// asynchronous, absolutely lightweight
6/// and dead simple bar for dwm and similar window managers
7pub struct AtomBlocksCli {
8    #[argh(subcommand)]
9    action: Option<CliActions>,
10
11    /// set log level to INFO
12    #[argh(switch, short = 'v', long = "verbose")]
13    verbose: bool,
14
15    /// set log level to TRACE (a lot of records, be careful)
16    #[argh(switch, long = "trace")]
17    trace: bool,
18
19    /// version
20    #[argh(switch, long = "version")]
21    version: bool,
22}
23
24impl AtomBlocksCli {
25    pub fn verbose(&self) -> bool {
26        self.verbose
27    }
28    pub fn trace(&self) -> bool {
29        self.trace
30    }
31    pub fn action(&self) -> Option<&CliActions> {
32        self.action.as_ref()
33    }
34    pub fn version(&self) -> bool {
35        self.version
36    }
37}
38
39#[derive(FromArgs, PartialEq, Debug)]
40#[argh(subcommand)]
41pub enum CliActions {
42    Run(CliActionRun),
43    Hit(CliActionHit),
44}
45
46#[derive(FromArgs, PartialEq, Debug)]
47/// Run the bar
48#[argh(subcommand, name = "run")]
49pub struct CliActionRun {
50    /// configuration file
51    #[argh(option, short = 'c', long = "config")]
52    config: Option<PathBuf>,
53}
54impl CliActionRun {
55    pub fn config(&self) -> Option<PathBuf> {
56        self.config.clone()
57    }
58}
59
60#[derive(FromArgs, PartialEq, Debug)]
61/// Asynchronously update the block specified in the ID
62#[argh(subcommand, name = "hit")]
63pub struct CliActionHit {
64    /// block id
65    #[argh(positional)]
66    id: u32,
67}
68impl CliActionHit {
69    pub fn id(&self) -> u32 {
70        self.id
71    }
72}