add --noheader option
This commit is contained in:
parent
8ef293a576
commit
cddfae5953
2 changed files with 5 additions and 2 deletions
|
@ -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()
|
||||||
}
|
}
|
||||||
|
|
|
@ -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) });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue