This commit is contained in:
JMARyA 2023-10-30 16:38:21 +01:00
parent cddfae5953
commit 2a2f55557d
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
5 changed files with 38 additions and 11 deletions

View file

@ -19,7 +19,7 @@ pub fn get_args() -> ArgMatches {
)
.arg(arg!(-f --filter <FILTER>... "Filter to apply to the documents").required(false))
.arg(
arg!(-c --column <COLUMN>... "Specify output columns")
arg!(-c --column <COLUMN>... "Specify output columns. You can rename the text displayed in the header using the `:` character like this: VariableName:OutputName")
.required(false)
.default_value("file.title:Title"),
)

View file

@ -86,10 +86,20 @@ impl Index {
if let Some(sort) = sort {
scope.sort_by(|a, b| {
let a = txd::parse(&a.get_key(&sort));
let b = txd::parse(&b.get_key(&sort));
let a_str = a.get_key(&sort);
let b_str = b.get_key(&sort);
let mut a = txd::parse(&a_str);
let mut b = txd::parse(&b_str);
a.order_with(&b)
log::debug!("Trying to order {a:?} and {b:?}",);
if !a.same_as(&b) {
log::debug!("trying to cast a to string because of different types");
a = txd::DataType::String(a_str);
b = txd::DataType::String(b_str);
}
a.order_with(&b).unwrap()
});
}
@ -169,7 +179,7 @@ impl Index {
a = txd::DataType::String(a_str);
}
if !a.compare(f.1, &b) {
if !a.compare(f.1, &b).unwrap() {
is_included = false;
}
}

View file

@ -70,7 +70,7 @@ fn main() {
i = i.apply(limit, offset, sort_by, reversed);
if group_by.is_some() {
let grouped = i.group_by(&group_by.unwrap());
let grouped = i.group_by(&group_by.clone().unwrap());
let grouped: HashMap<_, _> = grouped
.into_iter()
.map(|(key, val)| (key, val.create_table_data(&columns)))
@ -80,6 +80,7 @@ fn main() {
let mut data = serde_json::json!(
{
"columns": columns,
"groupby": group_by.unwrap(),
"results": grouped
}
);
@ -93,9 +94,24 @@ fn main() {
}
if std::io::stdout().is_terminal() {
for (group, val) in grouped {
let mut grouped_keys = grouped.iter().map(|(key, _)| key).collect::<Vec<_>>();
grouped_keys.sort_by(|a_str, b_str| {
let mut a = txd::parse(a_str);
let mut b = txd::parse(b_str);
log::debug!("Trying to order {a:?} and {b:?}",);
if !a.same_as(&b) {
log::debug!("trying to cast a to string because of different types");
a = txd::DataType::String(a_str.to_string());
b = txd::DataType::String(b_str.to_string());
}
a.order_with(&b).unwrap()
});
for group in grouped_keys {
println!("# {group}");
print_result(val, &headers);
print_result(grouped.get(group).unwrap().to_vec(), &headers);
}
} else {
let mut first = true;