Skip to content

Commit

Permalink
Update listing CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
ClementNerma committed Dec 20, 2023
1 parent 1608bf0 commit 40e3d2b
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "jumpy"
version = "0.4.0"
version = "0.4.1"
edition = "2021"
authors = ["Clément Nerma <clement.nerma@gmail.com>"]
license = "Apache-2.0"
Expand Down
10 changes: 5 additions & 5 deletions src/cmd.rs
Expand Up @@ -77,11 +77,11 @@ pub struct Query {

#[derive(Args)]
pub struct List {
#[clap(long, help = "Display the entry's ranking")]
pub ranking: bool,

#[clap(long, help = "Sort by score")]
pub sort_by_score: bool,
#[clap(
long,
help = "Only display paths (sort order will be alphabetic instead of score-based)"
)]
pub just_paths: bool,
}

#[derive(Args)]
Expand Down
12 changes: 5 additions & 7 deletions src/main.rs
Expand Up @@ -80,16 +80,14 @@ fn main() {
}
}

Action::List(List {
ranking,
sort_by_score,
}) => {
Action::List(List { just_paths }) => {
let mut entries = index.iter().collect::<Vec<_>>();

if !sort_by_score {
if just_paths {
entries.sort_by_key(|entry| entry.path);
} else {
entries.sort_by(|a, b| a.score.cmp(&b.score).reverse());
entries.sort_by_key(|entry| entry.score);
entries.reverse();
}

let longest_score = entries
Expand All @@ -100,7 +98,7 @@ fn main() {
.unwrap_or(0);

for IndexEntry { path, score } in entries {
if !ranking {
if just_paths {
println!("{path}");
} else {
println!("{score:>longest_score$} {path}");
Expand Down

0 comments on commit 40e3d2b

Please sign in to comment.