1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
use clap::{Parser, ValueHint};
use clio::Input;
use log::LevelFilter;

use crate::common::HasVerboseFlag;

use super::OutputFormat;

#[cfg(feature = "gzip")]
const BODYFILE_HELP: &str =
    "path to input file or '-' for stdin (files ending with .gz will be treated as being gzipped)";
#[cfg(not(feature = "gzip"))]
const BODYFILE_HELP: &str = "path to input file or '-' for stdin";

#[derive(Parser)]
#[clap(name="mactime2", author, version, about, long_about = None)]
pub struct Cli {
    #[clap(short('b'), num_args=1, value_parser, value_hint=ValueHint::FilePath, default_value="-", help=BODYFILE_HELP, display_order(100))]
    pub(crate) input_file: Input,

    /// output format, if not specified, default value is 'txt'
    #[clap(
        short('F'),
        num_args = 1,
        long("format"),
        value_enum,
        display_order(600)
    )]
    pub(crate) output_format: Option<OutputFormat>,

    /// output as CSV instead of TXT. This is a conveniance option, which is identical to `--format=csv`
    /// and will be removed in a future release. If you specified `--format` and `-d`, the latter will be ignored.
    #[clap(short('d'), num_args = 0, display_order(610))]
    pub(crate) csv_format: bool,

    /// output as JSON instead of TXT. This is a conveniance option, which is identical to `--format=json`
    /// and will be removed in a future release. If you specified `--format` and `-j`, the latter will be ignored.
    #[clap(short('j'), num_args = 0, display_order(620))]
    pub(crate) json_format: bool,

    /// name of offset of source timezone (or 'list' to display all possible values
    #[clap(short('f'), num_args = 1, long("from-timezone"), display_order(300))]
    pub(crate) src_zone: Option<String>,

    /// name of offset of destination timezone (or 'list' to display all possible values
    #[clap(short('t'), num_args = 1, long("to-timezone"), display_order(400))]
    pub(crate) dst_zone: Option<String>,

    // /// convert only, but do not sort
    // #[clap(short('c'), long("convert-only"), display_order(450))]
    // pub(crate) dont_sort: bool,
    /// strict mode: do not only warn, but abort if an error occurs
    #[clap(long("strict"), num_args = 0, display_order(500))]
    pub(crate) strict_mode: bool,

    #[clap(flatten)]
    pub(crate) verbose: clap_verbosity_flag::Verbosity,
}

impl HasVerboseFlag for Cli {
    fn log_level_filter(&self) -> LevelFilter {
        self.verbose.log_level_filter()
    }
}

impl Cli {
    pub fn verbose(&self) -> &clap_verbosity_flag::Verbosity {
        &self.verbose
    }

    pub fn src_zone(&self) -> &Option<String> {
        &self.src_zone
    }

    pub fn dst_zone(&self) -> &Option<String> {
        &self.dst_zone
    }
}