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

5
Cargo.lock generated
View file

@ -481,9 +481,9 @@ checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f"
[[package]] [[package]]
name = "rustix" name = "rustix"
version = "0.38.20" version = "0.38.21"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "67ce50cb2e16c2903e30d1cbccfd8387a74b9d4c938b6a4c5ec6cc7556f7a8a0" checksum = "2b426b0506e5d50a7d8dafcf2e81471400deb602392c7dd110815afb4eaf02a3"
dependencies = [ dependencies = [
"bitflags 2.4.1", "bitflags 2.4.1",
"errno", "errno",
@ -617,6 +617,7 @@ dependencies = [
[[package]] [[package]]
name = "txd" name = "txd"
version = "0.1.0" version = "0.1.0"
source = "git+https://git.hydrar.de/jmarya/txd#06f05e4a32c2bddf3e5f6347c96354feb109034f"
dependencies = [ dependencies = [
"chrono", "chrono",
"serde", "serde",

View file

@ -15,7 +15,7 @@ regex = "1.10.2"
serde = "1.0.189" serde = "1.0.189"
serde_yaml = "0.9.25" serde_yaml = "0.9.25"
walkdir = "2.4.0" walkdir = "2.4.0"
txd = { path = "../txd" } txd = { git = "https://git.hydrar.de/jmarya/txd" }
serde_json = "1.0.107" serde_json = "1.0.107"
comfy-table = "7.1.0" comfy-table = "7.1.0"
env_logger = "0.10.0" env_logger = "0.10.0"

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!(-f --filter <FILTER>... "Filter to apply to the documents").required(false))
.arg( .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) .required(false)
.default_value("file.title:Title"), .default_value("file.title:Title"),
) )

View file

@ -86,10 +86,20 @@ impl Index {
if let Some(sort) = sort { if let Some(sort) = sort {
scope.sort_by(|a, b| { scope.sort_by(|a, b| {
let a = txd::parse(&a.get_key(&sort)); let a_str = a.get_key(&sort);
let b = txd::parse(&b.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); a = txd::DataType::String(a_str);
} }
if !a.compare(f.1, &b) { if !a.compare(f.1, &b).unwrap() {
is_included = false; is_included = false;
} }
} }

View file

@ -70,7 +70,7 @@ fn main() {
i = i.apply(limit, offset, sort_by, reversed); i = i.apply(limit, offset, sort_by, reversed);
if group_by.is_some() { 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 let grouped: HashMap<_, _> = grouped
.into_iter() .into_iter()
.map(|(key, val)| (key, val.create_table_data(&columns))) .map(|(key, val)| (key, val.create_table_data(&columns)))
@ -80,6 +80,7 @@ fn main() {
let mut data = serde_json::json!( let mut data = serde_json::json!(
{ {
"columns": columns, "columns": columns,
"groupby": group_by.unwrap(),
"results": grouped "results": grouped
} }
); );
@ -93,9 +94,24 @@ fn main() {
} }
if std::io::stdout().is_terminal() { 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}"); println!("# {group}");
print_result(val, &headers); print_result(grouped.get(group).unwrap().to_vec(), &headers);
} }
} else { } else {
let mut first = true; let mut first = true;