Преглед изворни кода

Move clap to new module: args.rs

Johannes Hofmann пре 7 година
родитељ
комит
9c4535e568
2 измењених фајлова са 40 додато и 32 уклоњено
  1. 38
    0
      src/args.rs
  2. 2
    32
      src/main.rs

+ 38
- 0
src/args.rs Прегледај датотеку

@@ -0,0 +1,38 @@
1
+use clap;
2
+use clap::Arg;
3
+
4
+
5
+pub fn parse<'a>() -> clap::ArgMatches<'a> {
6
+    let matches = clap::App::new("DeltaMap")
7
+        .version(crate_version!())
8
+        .author(crate_authors!())
9
+        .about(crate_description!())
10
+        .arg(Arg::with_name("config")
11
+            .short("c")
12
+            .long("config")
13
+            .value_name("FILE")
14
+            .help("Set a custom config file")
15
+            .takes_value(true))
16
+        .arg(Arg::with_name("fps")
17
+            .long("fps")
18
+            .value_name("FPS")
19
+            .validator(|s| {
20
+                s.parse::<f64>()
21
+                    .map(|_| ())
22
+                    .map_err(|e| format!("{}", e))
23
+            })
24
+            .help("Set target frames per second (default is 60). \
25
+                This should equal the refresh rate of the display.")
26
+            .takes_value(true))
27
+        .arg(Arg::with_name("offline")
28
+            .long("offline")
29
+            .help("Do not use the network. \
30
+                Try to load tiles from the offline file system cache."))
31
+        .arg(Arg::with_name("sync")
32
+            .long("sync")
33
+            .help("Load tiles in a synchronous fashion. \
34
+                The UI is blocked while tiles are loading."))
35
+        .get_matches();
36
+
37
+    matches
38
+}

+ 2
- 32
src/main.rs Прегледај датотеку

@@ -10,9 +10,9 @@ extern crate reqwest;
10 10
 extern crate toml;
11 11
 extern crate xdg;
12 12
 
13
+pub mod args;
13 14
 #[macro_use]
14 15
 pub mod context;
15
-
16 16
 pub mod buffer;
17 17
 pub mod config;
18 18
 pub mod coord;
@@ -26,7 +26,6 @@ pub mod tile_atlas;
26 26
 pub mod tile_loader;
27 27
 pub mod tile_source;
28 28
 
29
-use clap::Arg;
30 29
 use coord::ScreenCoord;
31 30
 use glutin::{ControlFlow, ElementState, Event, GlContext, MouseButton, MouseScrollDelta, VirtualKeyCode, WindowEvent};
32 31
 use map_view_gl::MapViewGl;
@@ -178,36 +177,7 @@ fn dur_to_sec(dur: Duration) -> f64 {
178 177
 fn main() {
179 178
     env_logger::init();
180 179
 
181
-    let matches = clap::App::new("DeltaMap")
182
-        .version(crate_version!())
183
-        .author(crate_authors!())
184
-        .about(crate_description!())
185
-        .arg(Arg::with_name("config")
186
-            .short("c")
187
-            .long("config")
188
-            .value_name("FILE")
189
-            .help("Set a custom config file")
190
-            .takes_value(true))
191
-        .arg(Arg::with_name("fps")
192
-            .long("fps")
193
-            .value_name("FPS")
194
-            .validator(|s| {
195
-                s.parse::<f64>()
196
-                    .map(|_| ())
197
-                    .map_err(|e| format!("{}", e))
198
-            })
199
-            .help("Set target frames per second (default is 60). \
200
-                This should equal the refresh rate of the display.")
201
-            .takes_value(true))
202
-        .arg(Arg::with_name("offline")
203
-            .long("offline")
204
-            .help("Do not use the network. \
205
-                Try to load tiles from the offline file system cache."))
206
-        .arg(Arg::with_name("sync")
207
-            .long("sync")
208
-            .help("Load tiles in a synchronous fashion. \
209
-                Interaction is not possible while tiles are loading."))
210
-        .get_matches();
180
+    let matches = args::parse();
211 181
 
212 182
     let config = if let Some(config_path) = matches.value_of_os("config") {
213 183
             config::Config::from_toml_file(config_path).unwrap()