From f493b4b8c35ba812174d793e5b1f83a43f3db378 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sat, 28 Apr 2018 23:16:10 +0200 Subject: [PATCH] Fix: Allow second to be missing --- bin/core/imag-gps/src/main.rs | 24 +++++++++++++++++++----- 1 file 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 { - 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::>() + .collect::>(); + + 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) };