summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2018-04-28 23:16:10 +0200
committerMatthias Beyer <mail@beyermatthias.de>2018-04-28 23:18:02 +0200
commitf493b4b8c35ba812174d793e5b1f83a43f3db378 (patch)
tree612497f47b6aa8085a7f63449adda7ac88d9a090 /bin
parent5870fa078593811effe46ed31de93ed98d4e0a82 (diff)
Fix: Allow second to be missing
Diffstat (limited to 'bin')
-rw-r--r--bin/core/imag-gps/src/main.rs24
1 files changed, 19 insertions, 5 deletions
diff --git a/bin/core/imag-gps/src/main.rs b/bin/core/imag-gps/src/main.rs
index 502497a2..5378fac6 100644
--- a/bin/core/imag-gps/src/main.rs
+++ b/bin/core/imag-gps/src/main.rs
@@ -94,21 +94,35 @@ fn add(rt: &Runtime) {
.map_err_trace_exit_unwrap(1);
let c = {
- let parse = |value: &str| -> Vec<i8> {
- value.split(".")
+ let parse = |value: &str| -> (i32, i32, i32) {
+ debug!("Parsing '{}' into degree, minute and second", value);
+ let ary = value.split(".")
+ .map(|v| {debug!("Parsing = {}", v); v})
.map(FromStr::from_str)
.map(|elem| {
elem.or_else(|_| Err(GE::from(GEK::NumberConversionError)))
.map_err_trace_exit_unwrap(1)
})
- .collect::<Vec<i8>>()
+ .collect::<Vec<i32>>();
+
+ let degree = ary.get(0).unwrap_or_else(|| {
+ error!("Degree missing. This value is required.");
+ exit(1)
+ });
+ let minute = ary.get(1).unwrap_or_else(|| {
+ error!("Degree missing. This value is required.");
+ exit(1)
+ });
+ let second = ary.get(2).unwrap_or(&0);
+
+ (*degree, *minute, *second)
};
let long = parse(scmd.value_of("longitude").unwrap()); // unwrap safed by clap
let lati = parse(scmd.value_of("latitude").unwrap()); // unwrap safed by clap
- let long = GPSValue::new(long[0], long[1], long[2]);
- let lati = GPSValue::new(lati[0], lati[1], lati[2]);
+ let long = GPSValue::new(long.0, long.1, long.2);
+ let lati = GPSValue::new(lati.0, lati.1, lati.2);
Coordinates::new(long, lati)
};