summaryrefslogtreecommitdiff
path: root/src/birka-cli.rs
diff options
context:
space:
mode:
authorJakob L. Kreuze <zerodaysfordays@sdf.org>2020-06-14 18:43:48 -0400
committerJakob L. Kreuze <zerodaysfordays@sdf.org>2020-06-14 18:43:48 -0400
commit70f13d8277e71191b94443dde0758587e9e56115 (patch)
treef31f3cfc8ac2cf66497fb9138b43f12cfa8887be /src/birka-cli.rs
parentb53b1220360fc9c6a584415225ab0d54361b9cca (diff)
Completely rewrite database.rs
Diffstat (limited to 'src/birka-cli.rs')
-rw-r--r--src/birka-cli.rs41
1 files changed, 9 insertions, 32 deletions
diff --git a/src/birka-cli.rs b/src/birka-cli.rs
index 3fd5420..703da7d 100644
--- a/src/birka-cli.rs
+++ b/src/birka-cli.rs
@@ -51,20 +51,7 @@ fn main() {
std::process::exit(1);
}
let path = Path::new(&args[2]).canonicalize().unwrap();
- let hash = database::hash_file(&path).unwrap();
- let id = tb.import_image(&path, &hash).unwrap();
- for arg in args[3..].iter() {
- tb.add_tag(arg).unwrap();
- tb.tag_image(id, arg).unwrap();
- }
- }
- "id_for" => {
- if args.len() < 3 {
- eprintln!("usage: {} id_for PATH ", args[0]);
- std::process::exit(1);
- }
- let path = Path::new(&args[2]).canonicalize().unwrap();
- println!("{}", tb.image_id(&path).unwrap());
+ let id = tb.add_file(&path, &args[3..].to_vec()).unwrap();
}
"add_tags" => {
if args.len() < 3 {
@@ -72,10 +59,7 @@ fn main() {
std::process::exit(1);
}
let id = args[2].parse::<i64>().unwrap();
- for arg in args[3..].iter() {
- tb.add_tag(arg).unwrap();
- tb.tag_image(id, arg).unwrap();
- }
+ tb.tag_file(id, &args[3..].to_vec()).unwrap();
}
"remove_tags" => {
if args.len() < 3 {
@@ -83,23 +67,16 @@ fn main() {
std::process::exit(1);
}
let id = args[2].parse::<i64>().unwrap();
- for arg in args[3..].iter() {
- tb.untag_image(id, arg).unwrap();
- }
+ tb.untag_file(id, &args[3..].to_vec()).unwrap();
}
"query" => {
- let tags = args[2..].iter().map(|s| s.as_str()).collect::<Vec<&str>>();
- for tag in tags.iter() {
- if tb.tag_id(tag).is_err() {
- eprintln!("unknown tag: {}", tag);
- std::process::exit(1);
- }
+ if args.len() < 3 {
+ eprintln!("usage: {} query QUERY_STRING", args[0]);
+ std::process::exit(1);
}
- for image in tb.images_by_tags(&tags[..]).unwrap() {
- println!(
- "{},{},{}{}",
- image.id, image.blake2, image.orig_dir, image.filename
- );
+ let query = database::parse_query(&args[2]).unwrap();
+ for file in tb.query(&query, None).unwrap() {
+ println!("{}", file.path);
}
}
_ => {