diff options
| -rw-r--r-- | README.md | 7 | ||||
| -rw-r--r-- | src/birka-cli.rs | 22 |
2 files changed, 23 insertions, 6 deletions
@@ -65,6 +65,13 @@ $ birka-cli query ... ``` +The tag database is stored in a file, and the path of that file is dependent on +how the program is invoked. If, when parsing the command-line arguments, +`birka-cli` sees a `-o` or `--output` argument, the path following that argument +will be used. Alternatively, the `TB_PATH` environment variable can be +specified, but `-o` takes a higher precedence. If neither are specified, +"birka.db" in the current directory is used. + ### Web-Interface (API) The web interface for бирка-тян exposes a RESTful API for remotely interacting diff --git a/src/birka-cli.rs b/src/birka-cli.rs index 484d2ed..8396ef4 100644 --- a/src/birka-cli.rs +++ b/src/birka-cli.rs @@ -28,9 +28,12 @@ use std::env; use std::path::Path; fn main() { - let args: Vec<String> = env::args().collect(); + let mut args: Vec<String> = env::args().collect(); if args.len() < 2 || args.iter().any(|arg| arg == "-h" || arg == "--help") { println!("usage: {} ACTION [ARGS ...]", args[0]); + println!(); + println!("\t-o, --output [PATH]: Path to the tag database."); + println!(); println!("\tACTION: add [PATH] [TAGS ...]: index an image, optionally tagged."); println!("\tACTION: add_tags [PATH] [TAGS ...]: add tags to an indexed image."); println!("\tACTION: remove_tags [PATH] [TAGS ...]: remove tags from an indexed image."); @@ -38,12 +41,19 @@ fn main() { std::process::exit(1); } - let tb = if let Ok(val) = env::var("TB_PATH") { - TagDatabase::new(&val) - } else if let Some(dir) = dirs::config_dir() { - TagDatabase::new(&dir.join("birka.db")) + let tb = if let Some(i) = args.iter().position(|x| x == "-o" || x == "--output") { + // Ensure that a path follows the "-o" argument. + if i + 1 >= args.len() { + eprintln!("{} requires an argument", args[i]); + std::process::exit(1); + } + + args.remove(i); + TagDatabase::new(args.remove(i + 1)) + } else if let Ok(path) = std::env::var("TB_PATH") { + TagDatabase::new(path) } else { - TagDatabase::new(&Path::new("/tmp").join("birka.db")) + TagDatabase::new("./birka.db") } .unwrap(); |