bpaf improvements

* use latest published crate. This is a build fix: it was broken
  when the `exit_code` branch was deleted from the `bpaf` repo, even
  though the commit still exists!
  https://github.com/scottlamb/moonfire-nvr/pull/259

* clean up `db-dir` parsing redundancy, as suggested here:
  https://github.com/pacak/bpaf/discussions/165#discussioncomment-4983158
This commit is contained in:
Scott Lamb
2023-02-15 08:17:55 -08:00
parent ad48cf2e10
commit 0ffda11d4b
10 changed files with 24 additions and 34 deletions

View File

@@ -13,10 +13,7 @@ use std::path::PathBuf;
#[derive(Bpaf, Debug)]
#[bpaf(options)]
pub struct Args {
/// Directory holding the SQLite3 index database.
///
/// default: `/var/lib/moonfire-nvr/db`.
#[bpaf(argument("PATH"), fallback_with(crate::default_db_dir))]
#[bpaf(external(crate::parse_db_dir))]
db_dir: PathBuf,
/// Compares sample file lengths on disk to the database.

View File

@@ -23,10 +23,7 @@ mod users;
#[derive(Bpaf, Debug)]
#[bpaf(options)]
pub struct Args {
/// Directory holding the SQLite3 index database.
///
/// default: `/var/lib/moonfire-nvr/db`.
#[bpaf(argument("PATH"), fallback_with(crate::default_db_dir))]
#[bpaf(external(crate::parse_db_dir))]
db_dir: PathBuf,
}

View File

@@ -11,10 +11,7 @@ use std::path::PathBuf;
#[derive(Bpaf, Debug)]
#[bpaf(options)]
pub struct Args {
/// Directory holding the SQLite3 index database.
///
/// default: `/var/lib/moonfire-nvr/db`.
#[bpaf(argument("PATH"), fallback_with(crate::default_db_dir))]
#[bpaf(external(crate::parse_db_dir))]
db_dir: PathBuf,
}

View File

@@ -33,10 +33,7 @@ fn parse_flags(flags: String) -> Result<Vec<SessionFlag>, Error> {
#[derive(Bpaf, Debug, PartialEq, Eq)]
#[bpaf(options)]
pub struct Args {
/// Directory holding the SQLite3 index database.
///
/// default: `/var/lib/moonfire-nvr/db`.
#[bpaf(argument("PATH"), fallback_with(crate::default_db_dir))]
#[bpaf(external(crate::parse_db_dir))]
db_dir: PathBuf,
/// Creates a session with the given permissions, as a JSON object.
@@ -173,7 +170,7 @@ mod tests {
assert_eq!(
args,
Args {
db_dir: crate::default_db_dir().unwrap(),
db_dir: crate::DEFAULT_DB_DIR.into(),
domain: None,
curl_cookie_jar: None,
permissions: Some(crate::json::Permissions {

View File

@@ -12,7 +12,7 @@ use serde::Deserialize;
use crate::json::Permissions;
fn default_db_dir() -> PathBuf {
"/var/lib/moonfire-nvr/db".into()
crate::DEFAULT_DB_DIR.into()
}
fn default_ui_dir() -> PathBuf {

View File

@@ -20,10 +20,7 @@ use std::process::Command;
#[derive(Bpaf, Debug, PartialEq, Eq)]
#[bpaf(options)]
pub struct Args {
/// Directory holding the SQLite3 index database.
///
/// default: `/var/lib/moonfire-nvr/db`.
#[bpaf(fallback_with(crate::default_db_dir))]
#[bpaf(external(crate::parse_db_dir))]
db_dir: PathBuf,
/// Opens the database in read-only mode and locks it only for shared access.

View File

@@ -12,11 +12,7 @@ use failure::Error;
#[derive(Bpaf, Debug)]
#[bpaf(options)]
pub struct Args {
/// Directory holding the SQLite3 index database.
///
///
/// default: `/var/lib/moonfire-nvr/db`.
#[bpaf(argument("PATH"), fallback_with(crate::default_db_dir))]
#[bpaf(external(crate::parse_db_dir))]
db_dir: std::path::PathBuf,
/// When upgrading from schema version 1 to 2, the sample file directory.