Skip to content

Commit

Permalink
Add 'path' subcommand
Browse files Browse the repository at this point in the history
  • Loading branch information
ClementNerma committed May 10, 2022
1 parent 2ffe35d commit 9d31c36
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
13 changes: 13 additions & 0 deletions src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ pub enum Action {

#[clap(about = "Output the entire database (plain text)")]
Export(Export),

#[clap(about = "Get the path of the index file")]
Path(Path),
}

#[derive(Args)]
Expand Down Expand Up @@ -86,3 +89,13 @@ pub struct Clear {}

#[derive(Args)]
pub struct Export {}

#[derive(Args)]
pub struct Path {
#[clap(
short,
long,
help = "If the path contains invalid UTF-8 characters, don't fail and print it lossily instead"
)]
pub lossily: bool,
}
17 changes: 14 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,24 @@ fn main() {
index.remove(&path).unwrap();
}

Action::Clear(Clear {}) => {
index.clear();
}

Action::Optimize(Optimize {}) => index.optimize(),

Action::Export(Export {}) => index.export(),

Action::Clear(Clear {}) => {
index.clear();
}
Action::Path(Path { lossily }) => match index_file.to_str() {
Some(lossless) => println!("{}", lossless),
None => {
if lossily {
println!("{}", index_file.to_string_lossy())
} else {
fail("Path to index file contains invalid UTF-8 characters. Use --lossily to print it nonetheless.");
}
}
},
}

let updated = index.encode();
Expand Down

0 comments on commit 9d31c36

Please sign in to comment.