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
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
use clap::{App, Arg};
use clap::crate_version;

pub struct CliApp;

impl CliApp {
    pub fn create_cli_app(&self) -> App {
        let app = App::new("chopper")
            .version(crate_version!())
            .about("chopper is a simple streaming time series tool")
            .arg(Arg::with_name("input")
                .help("sets the input files to use; \nif missing, stdin will be used")
                .multiple(true))
            .arg(Arg::with_name("output")
                .long("output")
                .short("o")
                .help("output to a file")
                .takes_value(true)
                .value_name("FILE"))
            .arg(Arg::with_name("timezone")
                .long("timezone")
                .help("specify time zone for timestamp.")
                .takes_value(true)
                .case_insensitive(true)
                .value_name("ARG"))
            .arg(Arg::with_name("begin")
                .short("b")
                .long("begin")
                .help("set begin timestamp (inclusive); \ndate: yyyymmdd, time: hh:mm:ss")
                .takes_value(true)
                .value_name("TIMESTAMP"))
            .arg(Arg::with_name("end")
                .short("e")
                .long("end")
                .help("set end timestamp (exclusive); \ndate: yyyymmdd, time: hh:mm:ss")
                .takes_value(true)
                .value_name("TIMESTAMP"))
            .arg(Arg::with_name("backtrace")
                .long("backtrace")
                .help("print backtrace"))

            //  below are csv only
            .arg(Arg::with_name("csv_input_delimiter")
                .long("csv-in-delimiter")
                .help("csv only: input field/column delimiter")
                .takes_value(true)
                .default_value(",")
                .value_name("ARG"))
            .arg(Arg::with_name("csv_output_delimiter")
                .long("csv-out-delimiter")
                .help("csv only: output field/column delimiter")
                .takes_value(true)
                .default_value(",")
                .value_name("ARG"))

            // has header
            .arg(Arg::with_name("csv_has_header")
                .long("csv-has-header")
                .help("csv only: input files have header"))

            // print timestamp
            .arg(Arg::with_name("csv_print_ts")
                .long("csv-print-ts")
                .help("csv only: print timestamp as first column")
                .takes_value(true)
                .default_value("auto")
                .possible_values(&["true", "false", "auto"])
                .case_insensitive(true)
                .value_name("ARG"))

            // timestamp column
            .arg(Arg::with_name("csv_ts_col")
                .long("csv-ts")
                .help("csv only: specify the timestamp column index")
                .takes_value(true)
                .default_value("0")
                .value_name("ARG")
                .conflicts_with_all(&["csv_ts_col_date", "csv_ts_col_time"]))
            // timestamp column date
            .arg(Arg::with_name("csv_ts_col_date")
                .long("csv-ts-date")
                .help("csv only: specify the timestamp date column index. \
                        \nused when date and time are in separate columns")
                .takes_value(true)
                .value_name("ARG")
                .requires("csv_ts_col_time")
                .conflicts_with("csv_ts_col"))
            // timestamp column time
            .arg(Arg::with_name("csv_ts_col_time")
                .long("csv-ts-time")
                .help("csv only: specify the timestamp time column index. \
                        \nused when date and time are in separate columns")
                .takes_value(true)
                .value_name("ARG")
                .requires("csv_ts_col_date")
                .conflicts_with("csv_ts_col"))

            // timestamp format
            .arg(Arg::with_name("csv_ts_fmt")
                .long("csv-ts-fmt")
                .help("csv only: specify the timestamp datetime format")
                .takes_value(true)
                .value_name("ARG")
                .conflicts_with_all(&["csv_ts_fmt_date", "csv_ts_fmt_time"]))
            // timestamp format date
            .arg(Arg::with_name("csv_ts_fmt_date")
                .long("csv-ts-fmt-date")
                .help("csv only: specify the timestamp date format")
                .takes_value(true)
                .value_name("ARG")
                .requires("csv_ts_fmt_time")
                .conflicts_with("csv_ts_fmt_datetime"))
            // timestamp format time
            .arg(Arg::with_name("csv_ts_fmt_time")
                .long("csv-ts-fmt-time")
                .help("csv only: specify the timestamp time format \
                        \n[default: %H:%M:%S]")
                .takes_value(true)
                .value_name("ARG")
                .requires("csv_timestamp_format_date")
                .conflicts_with("csv_ts_fmt_datetime"));
        app
    }
}