allow specifying path to db on cli
parent
d56601cd61
commit
06d30433e5
|
@ -701,10 +701,15 @@ pub struct OpenResult {
|
||||||
|
|
||||||
pub const DATABASE_FILENAME: &str = "upend.sqlite3";
|
pub const DATABASE_FILENAME: &str = "upend.sqlite3";
|
||||||
|
|
||||||
pub fn open_upend<P: AsRef<Path>>(dirpath: P, reinitialize: bool) -> Result<OpenResult> {
|
pub fn open_upend<P: AsRef<Path>>(
|
||||||
|
dirpath: P,
|
||||||
|
db_path: Option<PathBuf>,
|
||||||
|
reinitialize: bool,
|
||||||
|
) -> Result<OpenResult> {
|
||||||
embed_migrations!("./migrations/upend/");
|
embed_migrations!("./migrations/upend/");
|
||||||
|
|
||||||
let database_path: PathBuf = dirpath.as_ref().join(DATABASE_FILENAME);
|
let database_path = db_path.unwrap_or_else(|| dirpath.as_ref().join(DATABASE_FILENAME));
|
||||||
|
|
||||||
if reinitialize {
|
if reinitialize {
|
||||||
let _ = fs::remove_file(&database_path);
|
let _ = fs::remove_file(&database_path);
|
||||||
}
|
}
|
||||||
|
|
13
src/main.rs
13
src/main.rs
|
@ -42,6 +42,11 @@ fn main() -> Result<()> {
|
||||||
.help("address and port to bind the Web interface on")
|
.help("address and port to bind the Web interface on")
|
||||||
.required(true),
|
.required(true),
|
||||||
)
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("DB_PATH")
|
||||||
|
.long("db-path")
|
||||||
|
.help("path to sqlite db file (\"$VAULT_PATH/upend.sqlite\" by default)"),
|
||||||
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("NO_BROWSER")
|
Arg::with_name("NO_BROWSER")
|
||||||
.long("no-browser")
|
.long("no-browser")
|
||||||
|
@ -73,8 +78,12 @@ fn main() -> Result<()> {
|
||||||
|
|
||||||
let vault_path = PathBuf::from(matches.value_of("DIRECTORY").unwrap());
|
let vault_path = PathBuf::from(matches.value_of("DIRECTORY").unwrap());
|
||||||
|
|
||||||
let open_result = database::open_upend(&vault_path, matches.is_present("REINITIALIZE"))
|
let open_result = database::open_upend(
|
||||||
.expect("failed to open database!");
|
&vault_path,
|
||||||
|
matches.value_of("DB_PATH").map(PathBuf::from),
|
||||||
|
matches.is_present("REINITIALIZE"),
|
||||||
|
)
|
||||||
|
.expect("failed to open database!");
|
||||||
|
|
||||||
let db_pool = open_result.pool;
|
let db_pool = open_result.pool;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue