-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathmod.rs
137 lines (124 loc) · 4.16 KB
/
mod.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
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
125
126
127
128
129
130
131
132
133
134
135
136
137
mod postgres_config;
mod redis_config;
use clap::{Args, Parser, Subcommand, ValueEnum};
use derivative::Derivative;
pub use postgres_config::PostgresConfig;
pub use redis_config::RedisConfig;
use std::{env, path::PathBuf};
#[derive(Parser, Debug)]
#[command(author, version)]
pub struct Client {
#[command(flatten)]
pub postgres_config: PostgresConfig,
#[command(flatten)]
pub redis_config: RedisConfig,
#[arg(long, env, value_enum, default_value_t = Color::Auto)]
pub color: Color,
#[command(subcommand)]
pub command: Commands,
}
#[derive(ValueEnum, Debug, Derivative, Clone)]
#[derivative(Default)]
pub enum Color {
Never,
Always,
#[derivative(Default)]
Auto,
}
#[derive(Subcommand, Debug)]
pub enum Commands {
Runserver(RunserverArgs),
Generate(GenerateArgs),
Clear(ClearArgs),
ImportRailjson(ImportRailjsonArgs),
ImportProfileSet(ImportProfileSetArgs),
OsmToRailjson(OsmToRailjsonArgs),
#[command(about, long_about = "Prints the OpenApi of the service")]
Openapi,
}
#[derive(Args, Debug, Derivative, Clone)]
#[derivative(Default)]
pub struct MapLayersConfig {
#[derivative(Default(value = "18"))]
#[arg(long, env, default_value_t = 18)]
pub max_zoom: u64,
/// Number maximum of tiles before we consider invalidating full Redis cache is required
#[derivative(Default(value = "250_000"))]
#[arg(long, env, default_value_t = 250_000)]
pub max_tiles: u64,
}
#[derive(Args, Debug, Derivative)]
#[derivative(Default)]
#[command(about, long_about = "Launch the server")]
pub struct RunserverArgs {
#[command(flatten)]
pub map_layers_config: MapLayersConfig,
#[derivative(Default(value = "8090"))]
#[arg(long, env = "EDITOAST_PORT", default_value_t = 8090)]
pub port: u16,
#[derivative(Default(value = r#""0.0.0.0".into()"#))]
#[arg(long, env = "EDITOAST_ADDRESS", default_value_t = String::from("0.0.0.0"))]
pub address: String,
#[derivative(Default(value = r#""http://localhost:8080".into()"#))]
#[clap(long, env = "OSRD_BACKEND_URL", default_value_t = String::from("http://localhost:8080"))]
pub backend_url: String,
#[clap(long, env = "OSRD_BACKEND_TOKEN", default_value_t = String::from(""))]
pub backend_token: String,
#[arg(long, env = "SENTRY_DSN")]
pub sentry_dsn: Option<String>,
#[arg(long, env = "SENTRY_ENV")]
pub sentry_env: Option<String>,
#[derivative(Default(value = r#""".into()"#))]
#[clap(long, env = "ROOT_PATH", default_value_t = String::new())]
pub root_path: String,
}
#[derive(Args, Debug)]
#[command(about, long_about = "Refresh infra generated data")]
pub struct GenerateArgs {
/// List of infra ids
pub infra_ids: Vec<u64>,
#[arg(short, long)]
/// Force the refresh of an infra (even if the generated version is up to date)
pub force: bool,
}
#[derive(Args, Debug)]
#[command(about, long_about = "Clear infra generated data")]
pub struct ClearArgs {
/// List of infra ids
pub infra_ids: Vec<u64>,
}
#[derive(Args, Debug)]
#[command(about, long_about = "Import an infra given a railjson file")]
pub struct ImportRailjsonArgs {
/// Infra name
pub infra_name: String,
/// Railjson file path
pub railjson_path: PathBuf,
/// Whether the import should refresh generated data
#[arg(short = 'g', long)]
pub generate: bool,
}
#[derive(Args, Debug)]
#[command(about, long_about = "Add a set of electrical profiles")]
pub struct ImportProfileSetArgs {
/// Electrical profile set name
pub name: String,
/// Electrical profile set file path
pub electrical_profile_set_path: PathBuf,
}
#[derive(Args, Debug)]
#[command(about, long_about = "Extracts a railjson from OpenStreetMap data")]
pub struct OsmToRailjsonArgs {
/// Input file in the OSM PBF format
pub osm_pbf_in: PathBuf,
/// Output file in Railjson format
pub railjson_out: PathBuf,
}
/// Retrieve the ROOT_URL env var. If not found returns default local url.
pub fn get_root_url() -> String {
env::var("ROOT_URL").unwrap_or(String::from("http://localhost:8090"))
}
/// Retrieve the app version (git describe)
pub fn get_app_version() -> Option<String> {
env::var("OSRD_GIT_DESCRIBE").ok()
}