-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.rs
58 lines (47 loc) · 2.5 KB
/
cli.rs
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
use chrono::NaiveDate;
use clap::Parser;
use islamic_prayer_times::{
DateRange, Elevation, Gmt, Latitude, Location, Longitude, Method, Params,
};
use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize)]
pub struct ParamsConfig {
pub params: Params,
pub location: Location,
pub date_range: Option<DateRange>,
}
#[derive(Debug, Parser)]
#[command(author, version, about, long_about = None)]
pub struct CliArgs {
// Required Greenwich Mean Time of geographical location unless --input_file or -i command line parameter is specified.
#[arg(short, long, value_parser = clap::value_parser!(Gmt), required_unless_present = "input_file_path")]
pub gmt: Option<Gmt>,
// Required latitude of geographical location unless --input_file or -i command line parameter is specified.
#[arg(short = 'l', long, value_parser = clap::value_parser!(Latitude), required_unless_present = "input_file_path")]
pub latitude: Option<Latitude>,
// Required longitude of geographical location unless --input_file or -i command line parameter is specified.
#[arg(short = 't', long, value_parser = clap::value_parser!(Longitude), required_unless_present = "input_file_path")]
pub longitude: Option<Longitude>,
// Optional elevation of geographical location the default value of which is 0m.
#[arg(short, long, value_parser = clap::value_parser!(Elevation), default_value = "0")]
pub elevation: Elevation,
// Optional calculation method the default value of which is Method::Isna.
#[arg(short, long, value_enum, default_value_t = Method::Isna)]
pub method: Method,
// Optional start date the default value of which is today.
#[arg(short, long, value_parser = clap::value_parser!(NaiveDate))]
pub start_date: Option<NaiveDate>,
// Optional end date the default value of which is today.
#[arg(short = 'n', long, value_parser = clap::value_parser!(NaiveDate))]
pub end_date: Option<NaiveDate>,
// Optional path to the file to read the JSON geographical location and calculation method parameters.
#[arg(short, long)]
pub input_file_path: Option<String>,
// Optional path to the file to write the calculated prayer times to as JSON.
#[arg(short, long)]
pub output_file_path: Option<String>,
// Optional path to the file to write the geographical location and calculation parameters to as JSON
// when the --input_file or -i command line parameter is not specified.
#[arg(short, long)]
pub params_file_path: Option<String>,
}