11use clap:: Parser ;
22
3+ #[ derive( Debug , Clone ) ]
4+ pub enum OverpassApiEndpoint {
5+ /// Use the API from overpass.osm.ch (which only includes Switzerland, good for quick testing)
6+ Switzerland ,
7+ /// Use the API from overpass-api.de (which includes the whole world)
8+ World ,
9+ /// Use a custom Overpass API URL
10+ Custom ( String ) ,
11+ }
12+
13+ impl OverpassApiEndpoint {
14+ /// Parse a string into an OverpassApiScope
15+ fn parse ( s : & str ) -> Result < Self , String > {
16+ match s {
17+ "switzerland" => Ok ( OverpassApiEndpoint :: Switzerland ) ,
18+ "world" => Ok ( OverpassApiEndpoint :: World ) ,
19+ url if url. starts_with ( "http://" ) || url. starts_with ( "https://" ) => {
20+ Ok ( OverpassApiEndpoint :: Custom ( url. to_string ( ) ) )
21+ }
22+ _ => Err ( format ! (
23+ "Invalid value '{}'. Expected 'switzerland', 'world', or a URL starting with http:// or https://" ,
24+ s
25+ ) ) ,
26+ }
27+ }
28+ }
29+
30+ impl OverpassApiEndpoint {
31+ /// Get the Overpass API URL for this scope
32+ pub fn get_url ( & self ) -> & str {
33+ match self {
34+ OverpassApiEndpoint :: Switzerland => "https://overpass.osm.ch/api/interpreter" ,
35+ OverpassApiEndpoint :: World => "https://overpass-api.de/api/interpreter" ,
36+ OverpassApiEndpoint :: Custom ( url) => url,
37+ }
38+ }
39+ }
40+
341/// Download worldwide charging station data from Overpass API and write them to
442/// a compressed JSON file.
543#[ derive( Parser , Debug ) ]
@@ -9,9 +47,14 @@ pub struct Args {
947 #[ arg( long, value_name = "BOOL" , default_value = "false" ) ]
1048 pub keep_intermediate : bool ,
1149
12- /// Overpass API interpreter URL
13- #[ arg( long, default_value = "https://overpass.osm.ch/api/interpreter" ) ]
14- pub overpass_url : String ,
50+ /// Overpass API to use ('switzerland', 'world', or a custom URL)
51+ ///
52+ /// The following hardcoded endpoints are supported:
53+ ///
54+ /// switzerland (https://overpass.osm.ch/api/interpreter),
55+ /// world (https://overpass-api.de/api/interpreter)
56+ #[ arg( long, value_parser = OverpassApiEndpoint :: parse) ]
57+ pub overpass_api_endpoint : OverpassApiEndpoint ,
1558
1659 /// Timeout in seconds for the Overpass query
1760 #[ arg( long, default_value = "900" ) ]
@@ -25,3 +68,10 @@ pub struct Args {
2568 #[ arg( long, default_value = "charging-stations-osm.json.gz" ) ]
2669 pub outfile_compressed : String ,
2770}
71+
72+ impl Args {
73+ /// Get the appropriate Overpass API URL based on the scope
74+ pub fn get_overpass_url ( & self ) -> & str {
75+ self . overpass_api_endpoint . get_url ( )
76+ }
77+ }
0 commit comments