add --noheader option

This commit is contained in:
JMARyA 2023-10-27 09:58:07 +02:00
parent 8ef293a576
commit cddfae5953
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
2 changed files with 5 additions and 2 deletions

View file

@ -26,5 +26,6 @@ pub fn get_args() -> ArgMatches {
.arg(arg!(-s --sortby <KEY> "Sort results based on specified key").required(false)) .arg(arg!(-s --sortby <KEY> "Sort results based on specified key").required(false))
.arg(arg!(-g --groupby <KEY> "Group results based on specified key").required(false)) .arg(arg!(-g --groupby <KEY> "Group results based on specified key").required(false))
.arg(arg!(-r --reverse "Reverse the results").required(false)) .arg(arg!(-r --reverse "Reverse the results").required(false))
.arg(arg!(--noheader "Dont print header in CSV mode. Useful for scripting").required(false))
.get_matches() .get_matches()
} }

View file

@ -15,6 +15,8 @@ fn main() {
let output_json = args.get_flag("json"); let output_json = args.get_flag("json");
let no_header = args.get_flag("noheader");
let limit: usize = args.get_one::<String>("limit").unwrap().parse().unwrap(); let limit: usize = args.get_one::<String>("limit").unwrap().parse().unwrap();
let offset: usize = args.get_one::<String>("offset").unwrap().parse().unwrap(); let offset: usize = args.get_one::<String>("offset").unwrap().parse().unwrap();
@ -99,7 +101,7 @@ fn main() {
let mut first = true; let mut first = true;
for (_, val) in grouped { for (_, val) in grouped {
if first { if first {
print_csv(val, Some(&headers)); print_csv(val, if no_header { None } else { Some(&headers) });
first = false; first = false;
continue; continue;
} }
@ -129,7 +131,7 @@ fn main() {
if std::io::stdout().is_terminal() { if std::io::stdout().is_terminal() {
print_result(data, &headers); print_result(data, &headers);
} else { } else {
print_csv(data, Some(&headers)); print_csv(data, if no_header { None } else { Some(&headers) });
} }
} }