mirror of
https://github.com/pimalaya/himalaya.git
synced 2026-06-17 13:17:55 +08:00
add silent flag (#74)
This commit is contained in:
+14
-8
@@ -1,11 +1,17 @@
|
||||
use clap::Arg;
|
||||
|
||||
pub fn output_arg<'a>() -> Arg<'a, 'a> {
|
||||
Arg::with_name("output")
|
||||
.long("output")
|
||||
.short("o")
|
||||
.help("Defines the output format")
|
||||
.value_name("STRING")
|
||||
.possible_values(&["plain", "json"])
|
||||
.default_value("plain")
|
||||
pub fn output_args<'a>() -> Vec<Arg<'a, 'a>> {
|
||||
vec![
|
||||
Arg::with_name("output")
|
||||
.long("output")
|
||||
.short("o")
|
||||
.help("Defines the output format")
|
||||
.value_name("STRING")
|
||||
.possible_values(&["plain", "json"])
|
||||
.default_value("plain"),
|
||||
Arg::with_name("silent")
|
||||
.long("silent")
|
||||
.short("s")
|
||||
.help("Disables any output"),
|
||||
]
|
||||
}
|
||||
|
||||
+9
-7
@@ -41,13 +41,15 @@ pub fn run_cmd(cmd: &str) -> Result<String> {
|
||||
Ok(String::from_utf8(output.stdout)?)
|
||||
}
|
||||
|
||||
pub fn print<T: fmt::Display + Serialize>(output_type: &str, item: T) -> Result<()> {
|
||||
match output_type {
|
||||
"json" => print!(
|
||||
"{}",
|
||||
serde_json::to_string(&item).chain_err(|| "Could not decode JSON")?
|
||||
),
|
||||
"text" | _ => println!("{}", item.to_string()),
|
||||
pub fn print<T: fmt::Display + Serialize>(output_type: &str, silent: &bool, item: T) -> Result<()> {
|
||||
if silent == &false {
|
||||
match output_type {
|
||||
"json" => print!(
|
||||
"{}",
|
||||
serde_json::to_string(&item).chain_err(|| "Could not decode JSON")?
|
||||
),
|
||||
"text" | _ => println!("{}", item.to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user