Procházet zdrojové kódy

Parse command line arguments, allow setting the config file

Johannes Hofmann před 8 roky
rodič
revize
68bbe544e5
3 změnil soubory, kde provedl 104 přidání a 4 odebrání
  1. 80
    0
      Cargo.lock
  2. 1
    0
      Cargo.toml
  3. 23
    4
      src/main.rs

+ 80
- 0
Cargo.lock Zobrazit soubor

@@ -8,6 +8,21 @@ name = "android_glue"
8 8
 version = "0.2.3"
9 9
 source = "registry+https://github.com/rust-lang/crates.io-index"
10 10
 
11
+[[package]]
12
+name = "ansi_term"
13
+version = "0.10.2"
14
+source = "registry+https://github.com/rust-lang/crates.io-index"
15
+
16
+[[package]]
17
+name = "atty"
18
+version = "0.2.6"
19
+source = "registry+https://github.com/rust-lang/crates.io-index"
20
+dependencies = [
21
+ "libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)",
22
+ "termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
23
+ "winapi 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
24
+]
25
+
11 26
 [[package]]
12 27
 name = "backtrace"
13 28
 version = "0.3.5"
@@ -91,6 +106,20 @@ dependencies = [
91 106
  "libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)",
92 107
 ]
93 108
 
109
+[[package]]
110
+name = "clap"
111
+version = "2.29.1"
112
+source = "registry+https://github.com/rust-lang/crates.io-index"
113
+dependencies = [
114
+ "ansi_term 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)",
115
+ "atty 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
116
+ "bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
117
+ "strsim 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
118
+ "textwrap 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
119
+ "unicode-width 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
120
+ "vec_map 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
121
+]
122
+
94 123
 [[package]]
95 124
 name = "coco"
96 125
 version = "0.1.1"
@@ -183,6 +212,7 @@ dependencies = [
183 212
 name = "deltamap"
184 213
 version = "0.1.0"
185 214
 dependencies = [
215
+ "clap 2.29.1 (registry+https://github.com/rust-lang/crates.io-index)",
186 216
  "gl 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
187 217
  "gl_generator 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
188 218
  "image 0.18.0 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -815,6 +845,14 @@ name = "redox_syscall"
815 845
 version = "0.1.37"
816 846
 source = "registry+https://github.com/rust-lang/crates.io-index"
817 847
 
848
+[[package]]
849
+name = "redox_termios"
850
+version = "0.1.1"
851
+source = "registry+https://github.com/rust-lang/crates.io-index"
852
+dependencies = [
853
+ "redox_syscall 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)",
854
+]
855
+
818 856
 [[package]]
819 857
 name = "relay"
820 858
 version = "0.1.0"
@@ -991,6 +1029,11 @@ name = "smallvec"
991 1029
 version = "0.2.1"
992 1030
 source = "registry+https://github.com/rust-lang/crates.io-index"
993 1031
 
1032
+[[package]]
1033
+name = "strsim"
1034
+version = "0.6.0"
1035
+source = "registry+https://github.com/rust-lang/crates.io-index"
1036
+
994 1037
 [[package]]
995 1038
 name = "take"
996 1039
 version = "0.1.0"
@@ -1004,6 +1047,24 @@ dependencies = [
1004 1047
  "rand 0.3.20 (registry+https://github.com/rust-lang/crates.io-index)",
1005 1048
 ]
1006 1049
 
1050
+[[package]]
1051
+name = "termion"
1052
+version = "1.5.1"
1053
+source = "registry+https://github.com/rust-lang/crates.io-index"
1054
+dependencies = [
1055
+ "libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)",
1056
+ "redox_syscall 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)",
1057
+ "redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
1058
+]
1059
+
1060
+[[package]]
1061
+name = "textwrap"
1062
+version = "0.9.0"
1063
+source = "registry+https://github.com/rust-lang/crates.io-index"
1064
+dependencies = [
1065
+ "unicode-width 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
1066
+]
1067
+
1007 1068
 [[package]]
1008 1069
 name = "time"
1009 1070
 version = "0.1.39"
@@ -1112,6 +1173,11 @@ name = "unicode-normalization"
1112 1173
 version = "0.1.5"
1113 1174
 source = "registry+https://github.com/rust-lang/crates.io-index"
1114 1175
 
1176
+[[package]]
1177
+name = "unicode-width"
1178
+version = "0.1.4"
1179
+source = "registry+https://github.com/rust-lang/crates.io-index"
1180
+
1115 1181
 [[package]]
1116 1182
 name = "url"
1117 1183
 version = "1.6.0"
@@ -1144,6 +1210,11 @@ name = "vcpkg"
1144 1210
 version = "0.2.2"
1145 1211
 source = "registry+https://github.com/rust-lang/crates.io-index"
1146 1212
 
1213
+[[package]]
1214
+name = "vec_map"
1215
+version = "0.8.0"
1216
+source = "registry+https://github.com/rust-lang/crates.io-index"
1217
+
1147 1218
 [[package]]
1148 1219
 name = "version_check"
1149 1220
 version = "0.1.3"
@@ -1213,6 +1284,8 @@ dependencies = [
1213 1284
 [metadata]
1214 1285
 "checksum adler32 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6cbd0b9af8587c72beadc9f72d35b9fbb070982c9e6203e46e93f10df25f8f45"
1215 1286
 "checksum android_glue 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "000444226fcff248f2bc4c7625be32c63caccfecc2723a2b9f78a7487a49c407"
1287
+"checksum ansi_term 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6b3568b48b7cefa6b8ce125f9bb4989e52fbcc29ebea88df04cc7c5f12f70455"
1288
+"checksum atty 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "8352656fd42c30a0c3c89d26dea01e3b77c0ab2af18230835c15e2e13cd51859"
1216 1289
 "checksum backtrace 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "ebbbf59b1c43eefa8c3ede390fcc36820b4999f7914104015be25025e0d62af2"
1217 1290
 "checksum backtrace-sys 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "44585761d6161b0f57afc49482ab6bd067e4edef48c12a152c237eb0203f7661"
1218 1291
 "checksum base64 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "229d032f1a99302697f10b27167ae6d03d49d032e6a8e2550e8d3fc13356d2b4"
@@ -1225,6 +1298,7 @@ dependencies = [
1225 1298
 "checksum cc 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "deaf9ec656256bb25b404c51ef50097207b9cbb29c933d31f92cae5a8a0ffee0"
1226 1299
 "checksum cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d4c819a1287eb618df47cc647173c5c4c66ba19d888a6e50d605672aed3140de"
1227 1300
 "checksum cgl 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "86765cb42c2a2c497e142af72517c1b4d7ae5bb2f25dfa77a5c69642f2342d89"
1301
+"checksum clap 2.29.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8f4a2b3bb7ef3c672d7c13d15613211d5a6976b6892c598b0fcb5d40765f19c2"
1228 1302
 "checksum coco 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c06169f5beb7e31c7c67ebf5540b8b472d23e3eade3b2ec7d1f5b504a85f91bd"
1229 1303
 "checksum cocoa 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac0d785ff4faf0ff23d7b5561346bb50dc7ef9a11cb0e65e07ef776b7752938f"
1230 1304
 "checksum color_quant 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a475fc4af42d83d28adf72968d9bcfaf035a1a9381642d8e85d8a04957767b0d"
@@ -1307,6 +1381,7 @@ dependencies = [
1307 1381
 "checksum rayon 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ed02d09394c94ffbdfdc755ad62a132e94c3224a8354e78a1200ced34df12edf"
1308 1382
 "checksum rayon-core 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e64b609139d83da75902f88fd6c01820046840a18471e4dfcd5ac7c0f46bea53"
1309 1383
 "checksum redox_syscall 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)" = "0d92eecebad22b767915e4d529f89f28ee96dbbf5a4810d2b844373f136417fd"
1384
+"checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76"
1310 1385
 "checksum relay 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f301bafeb60867c85170031bdb2fcf24c8041f33aee09e7b116a58d4e9f781c5"
1311 1386
 "checksum reqwest 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "3161ca63fd11ce36c7718af239e6492a25a3dbfcec54240f959b9d816cf42413"
1312 1387
 "checksum rustc-demangle 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "aee45432acc62f7b9a108cc054142dac51f979e69e71ddce7d6fc7adf29e817e"
@@ -1327,8 +1402,11 @@ dependencies = [
1327 1402
 "checksum slab 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "17b4fcaed89ab08ef143da37bc52adbcc04d4a69014f4c1208d6b51f0c47bc23"
1328 1403
 "checksum slab 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fdeff4cd9ecff59ec7e3744cbca73dfe5ac35c2aedb2cfba8a1c715a18912e9d"
1329 1404
 "checksum smallvec 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4c8cbcd6df1e117c2210e13ab5109635ad68a929fcbb8964dc965b76cb5ee013"
1405
+"checksum strsim 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b4d15c810519a91cf877e7e36e63fe068815c678181439f2f29e2562147c3694"
1330 1406
 "checksum take 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b157868d8ac1f56b64604539990685fa7611d8fa9e5476cf0c02cf34d32917c5"
1331 1407
 "checksum tempdir 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "87974a6f5c1dfb344d733055601650059a3363de2a6104819293baff662132d6"
1408
+"checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096"
1409
+"checksum textwrap 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c0b59b6b4b44d867f1370ef1bd91bfb262bf07bf0ae65c202ea2fbc16153b693"
1332 1410
 "checksum time 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)" = "a15375f1df02096fb3317256ce2cee6a1f42fc84ea5ad5fc8c421cfe40c73098"
1333 1411
 "checksum tokio-core 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "52b4e32d8edbf29501aabb3570f027c6ceb00ccef6538f4bddba0200503e74e8"
1334 1412
 "checksum tokio-io 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "514aae203178929dbf03318ad7c683126672d4d96eccb77b29603d33c9e25743"
@@ -1340,10 +1418,12 @@ dependencies = [
1340 1418
 "checksum unicase 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "284b6d3db520d67fbe88fd778c21510d1b0ba4a551e5d0fbb023d33405f6de8a"
1341 1419
 "checksum unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5"
1342 1420
 "checksum unicode-normalization 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "51ccda9ef9efa3f7ef5d91e8f9b83bbe6955f9bf86aec89d5cce2c874625920f"
1421
+"checksum unicode-width 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "bf3a113775714a22dcb774d8ea3655c53a32debae63a063acc00a91cc586245f"
1343 1422
 "checksum url 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fa35e768d4daf1d85733418a49fb42e10d7f633e394fccab4ab7aba897053fe2"
1344 1423
 "checksum user32-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4ef4711d107b21b410a3a974b1204d9accc8b10dad75d8324b5d755de1617d47"
1345 1424
 "checksum uuid 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "bcc7e3b898aa6f6c08e5295b6c89258d1331e9ac578cc992fb818759951bdc22"
1346 1425
 "checksum vcpkg 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9e0a7d8bed3178a8fb112199d466eeca9ed09a14ba8ad67718179b4fd5487d0b"
1426
+"checksum vec_map 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "887b5b631c2ad01628bbbaa7dd4c869f80d3186688f8d0b6f58774fbe324988c"
1347 1427
 "checksum version_check 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "6b772017e347561807c1aa192438c5fd74242a670a6cffacc40f2defd1dc069d"
1348 1428
 "checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a"
1349 1429
 "checksum winapi 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "b09fb3b6f248ea4cd42c9a65113a847d612e17505d6ebd1f7357ad68a8bf8693"

+ 1
- 0
Cargo.toml Zobrazit soubor

@@ -4,6 +4,7 @@ version = "0.1.0"
4 4
 authors = ["Johannes Hofmann <mail@b-r-u.org>"]
5 5
 
6 6
 [dependencies]
7
+clap = "2.29"
7 8
 gl = "0.9"
8 9
 image = "0.18"
9 10
 linked-hash-map = "0.5.0"

+ 23
- 4
src/main.rs Zobrazit soubor

@@ -1,3 +1,4 @@
1
+extern crate clap;
1 2
 extern crate glutin;
2 3
 extern crate image;
3 4
 extern crate linked_hash_map;
@@ -5,7 +6,6 @@ extern crate reqwest;
5 6
 extern crate toml;
6 7
 extern crate xdg;
7 8
 
8
-
9 9
 #[macro_use]
10 10
 mod context;
11 11
 
@@ -22,14 +22,16 @@ mod tile_cache_gl;
22 22
 mod tile_loader;
23 23
 mod tile_source;
24 24
 
25
+use clap::Arg;
25 26
 use coord::ScreenCoord;
26 27
 use glutin::{ElementState, Event, MouseButton, MouseScrollDelta, VirtualKeyCode};
27 28
 use map_view_gl::MapViewGl;
28 29
 use std::time::{Duration, Instant};
29 30
 use tile_source::TileSource;
30 31
 
31
-#[cfg(target_os = "android")]
32
-android_start!(main);
32
+
33
+static VERSION: &'static str = "0.1.0";
34
+
33 35
 
34 36
 #[derive(Copy, Clone, Debug, PartialEq, Eq)]
35 37
 enum Action {
@@ -155,7 +157,24 @@ fn handle_event(event: &Event, map: &mut MapViewGl, input_state: &mut InputState
155 157
 }
156 158
 
157 159
 fn main() {
158
-    let config = config::Config::load().unwrap();
160
+    let matches = clap::App::new("DeltaMap")
161
+        .version(VERSION)
162
+        .author("Johannes Hofmann <mail@b-r-u.org>")
163
+        .about("A map viewer")
164
+        .arg(Arg::with_name("config")
165
+            .short("c")
166
+            .long("config")
167
+            .value_name("FILE")
168
+            .help("Set a custom config file")
169
+            .takes_value(true))
170
+        .get_matches();
171
+
172
+    let config = if let Some(config_path) = matches.value_of_os("config") {
173
+            config::Config::from_toml_file(config_path).unwrap()
174
+        } else {
175
+            config::Config::load().unwrap()
176
+        };
177
+
159 178
     let mut sources = TileSources::new(config.tile_sources()).unwrap();
160 179
 
161 180
     let mut window = glutin::WindowBuilder::new().build().unwrap();