From a6bbcd65f494e15e9292047901c69f82beba2368 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sun, 20 Oct 2019 15:04:55 +0200 Subject: [PATCH] Change output to not have quotes when printing string, int, float or bool Signed-off-by: Matthias Beyer --- bin/core/imag-header/src/main.rs | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/bin/core/imag-header/src/main.rs b/bin/core/imag-header/src/main.rs index 1205a6ad..1366726c 100644 --- a/bin/core/imag-header/src/main.rs +++ b/bin/core/imag-header/src/main.rs @@ -47,10 +47,12 @@ extern crate libimagutil; use std::io::Write; use std::str::FromStr; +use std::string::ToString; use clap::ArgMatches; use filters::filter::Filter; use failure::Error; +use toml::Value; use libimagerror::exit::ExitCode; use libimagerror::exit::ExitUnwrap; @@ -134,10 +136,23 @@ fn read<'a, 'e, I>(rt: &Runtime, mtch: &ArgMatches<'a>, iter: I) -> i32 .map_err_trace_exit_unwrap() .map(|value| { trace!("Processing headers: Got value {:?}", value); - writeln!(output, "{}", value) - .to_exit_code() - .map(|_| accu) - .unwrap_or_else(ExitCode::code) + + let string_representation = match value { + Value::String(s) => Some(s.to_owned()), + Value::Integer(i) => Some(i.to_string()), + Value::Float(f) => Some(f.to_string()), + Value::Boolean(b) => Some(b.to_string()), + _ => None, + }; + + if let Some(repr) = string_representation { + writeln!(output, "{}", repr) + } else { + writeln!(output, "{}", value) + } + .to_exit_code() + .map(|_| accu) + .unwrap_or_else(ExitCode::code) }) .unwrap_or_else(|| { // if value not present and configured