mirror of
https://github.com/scottlamb/moonfire-nvr.git
synced 2025-11-28 05:04:15 -05:00
tweak bpaf usage message
As discussed here: https://github.com/pacak/bpaf/discussions/165#discussioncomment-4967176 I also snuck in a conversion from `lazy_static` to `once_cell`, rather than adding another usage of the former.
This commit is contained in:
@@ -9,7 +9,9 @@ use db::check;
|
||||
use failure::Error;
|
||||
use std::path::PathBuf;
|
||||
|
||||
/// Checks database integrity (like fsck).
|
||||
#[derive(Bpaf, Debug)]
|
||||
#[bpaf(options)]
|
||||
pub struct Args {
|
||||
/// Directory holding the SQLite3 index database.
|
||||
///
|
||||
@@ -40,6 +42,10 @@ pub struct Args {
|
||||
trash_corrupt_rows: bool,
|
||||
}
|
||||
|
||||
pub fn subcommand() -> impl bpaf::Parser<Args> {
|
||||
crate::subcommand(args(), "check")
|
||||
}
|
||||
|
||||
pub fn run(args: Args) -> Result<i32, Error> {
|
||||
let (_db_dir, mut conn) = super::open_conn(&args.db_dir, super::OpenMode::ReadWrite)?;
|
||||
check::run(
|
||||
|
||||
@@ -19,7 +19,9 @@ mod cameras;
|
||||
mod dirs;
|
||||
mod users;
|
||||
|
||||
/// Interactively edits configuration.
|
||||
#[derive(Bpaf, Debug)]
|
||||
#[bpaf(options)]
|
||||
pub struct Args {
|
||||
/// Directory holding the SQLite3 index database.
|
||||
///
|
||||
@@ -28,6 +30,10 @@ pub struct Args {
|
||||
db_dir: PathBuf,
|
||||
}
|
||||
|
||||
pub fn subcommand() -> impl bpaf::Parser<Args> {
|
||||
crate::subcommand(args(), "config")
|
||||
}
|
||||
|
||||
pub fn run(args: Args) -> Result<i32, Error> {
|
||||
let (_db_dir, conn) = super::open_conn(&args.db_dir, super::OpenMode::ReadWrite)?;
|
||||
let clocks = clock::RealClocks {};
|
||||
|
||||
@@ -7,7 +7,9 @@ use failure::Error;
|
||||
use log::info;
|
||||
use std::path::PathBuf;
|
||||
|
||||
/// Initializes a database.
|
||||
#[derive(Bpaf, Debug)]
|
||||
#[bpaf(options)]
|
||||
pub struct Args {
|
||||
/// Directory holding the SQLite3 index database.
|
||||
///
|
||||
@@ -16,6 +18,10 @@ pub struct Args {
|
||||
db_dir: PathBuf,
|
||||
}
|
||||
|
||||
pub fn subcommand() -> impl bpaf::Parser<Args> {
|
||||
crate::subcommand(args(), "init")
|
||||
}
|
||||
|
||||
pub fn run(args: Args) -> Result<i32, Error> {
|
||||
let (_db_dir, mut conn) = super::open_conn(&args.db_dir, super::OpenMode::Create)?;
|
||||
|
||||
|
||||
@@ -24,7 +24,14 @@ fn parse_flags(flags: String) -> Result<Vec<SessionFlag>, Error> {
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Logs in a user, returning the session cookie.
|
||||
///
|
||||
///
|
||||
/// This is a privileged command that directly accesses the database. It doesn't check the
|
||||
/// user's password and even can be used to create sessions with permissions the user doesn't
|
||||
/// have.
|
||||
#[derive(Bpaf, Debug, PartialEq, Eq)]
|
||||
#[bpaf(options)]
|
||||
pub struct Args {
|
||||
/// Directory holding the SQLite3 index database.
|
||||
///
|
||||
@@ -64,6 +71,10 @@ pub struct Args {
|
||||
username: String,
|
||||
}
|
||||
|
||||
pub fn subcommand() -> impl bpaf::Parser<Args> {
|
||||
crate::subcommand(args(), "login")
|
||||
}
|
||||
|
||||
pub fn run(args: Args) -> Result<i32, Error> {
|
||||
let clocks = clock::RealClocks {};
|
||||
let (_db_dir, conn) = super::open_conn(&args.db_dir, super::OpenMode::ReadWrite)?;
|
||||
@@ -148,12 +159,9 @@ fn curl_cookie(cookie: &str, flags: i32, domain: &str) -> String {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
use bpaf::Parser;
|
||||
|
||||
#[test]
|
||||
fn parse_args() {
|
||||
let args = args()
|
||||
.to_options()
|
||||
.run_inner(bpaf::Args::from(&[
|
||||
"--permissions",
|
||||
"{\"viewVideo\": true}",
|
||||
|
||||
@@ -25,7 +25,9 @@ use self::config::ConfigFile;
|
||||
|
||||
mod config;
|
||||
|
||||
/// Runs the server, saving recordings and allowing web access.
|
||||
#[derive(Bpaf, Debug)]
|
||||
#[bpaf(options)]
|
||||
pub struct Args {
|
||||
/// Path to configuration file.
|
||||
///
|
||||
@@ -40,6 +42,10 @@ pub struct Args {
|
||||
read_only: bool,
|
||||
}
|
||||
|
||||
pub fn subcommand() -> impl bpaf::Parser<Args> {
|
||||
crate::subcommand(args(), "run")
|
||||
}
|
||||
|
||||
// These are used in a hack to get the name of the current time zone (e.g. America/Los_Angeles).
|
||||
// They seem to be correct for Linux and macOS at least.
|
||||
const LOCALTIME_PATH: &str = "/etc/localtime";
|
||||
|
||||
@@ -12,7 +12,13 @@ use std::os::unix::process::CommandExt;
|
||||
use std::path::PathBuf;
|
||||
use std::process::Command;
|
||||
|
||||
/// Runs a SQLite3 shell on Moonfire NVR's index database.
|
||||
///
|
||||
///
|
||||
/// Note this locks the database to prevent simultaneous access with a running server. The
|
||||
/// server maintains cached state which could be invalidated otherwise.
|
||||
#[derive(Bpaf, Debug, PartialEq, Eq)]
|
||||
#[bpaf(options)]
|
||||
pub struct Args {
|
||||
/// Directory holding the SQLite3 index database.
|
||||
///
|
||||
@@ -33,6 +39,10 @@ pub struct Args {
|
||||
arg: Vec<OsString>,
|
||||
}
|
||||
|
||||
pub fn subcommand() -> impl bpaf::Parser<Args> {
|
||||
crate::subcommand(args(), "sql")
|
||||
}
|
||||
|
||||
pub fn run(args: Args) -> Result<i32, Error> {
|
||||
let mode = if args.read_only {
|
||||
OpenMode::ReadOnly
|
||||
@@ -59,12 +69,9 @@ pub fn run(args: Args) -> Result<i32, Error> {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
use bpaf::Parser;
|
||||
|
||||
#[test]
|
||||
fn parse_args() {
|
||||
let args = args()
|
||||
.to_options()
|
||||
.run_inner(bpaf::Args::from(&[
|
||||
"--db-dir",
|
||||
"/foo/bar",
|
||||
|
||||
@@ -5,7 +5,9 @@
|
||||
use bpaf::Bpaf;
|
||||
use failure::Error;
|
||||
|
||||
/// Translates between integer and human-readable timestamps.
|
||||
#[derive(Bpaf, Debug)]
|
||||
#[bpaf(options)]
|
||||
pub struct Args {
|
||||
/// Timestamp(s) to translate.
|
||||
///
|
||||
@@ -17,6 +19,10 @@ pub struct Args {
|
||||
timestamps: Vec<String>,
|
||||
}
|
||||
|
||||
pub fn subcommand() -> impl bpaf::Parser<Args> {
|
||||
crate::subcommand(args(), "ts")
|
||||
}
|
||||
|
||||
pub fn run(args: Args) -> Result<i32, Error> {
|
||||
for timestamp in &args.timestamps {
|
||||
let t = db::recording::Time::parse(timestamp)?;
|
||||
|
||||
@@ -8,7 +8,9 @@ use bpaf::Bpaf;
|
||||
/// See `guide/schema.md` for more information.
|
||||
use failure::Error;
|
||||
|
||||
/// Upgrades to the latest database schema.
|
||||
#[derive(Bpaf, Debug)]
|
||||
#[bpaf(options)]
|
||||
pub struct Args {
|
||||
/// Directory holding the SQLite3 index database.
|
||||
///
|
||||
@@ -35,6 +37,10 @@ pub struct Args {
|
||||
no_vacuum: bool,
|
||||
}
|
||||
|
||||
pub fn subcommand() -> impl bpaf::Parser<Args> {
|
||||
crate::subcommand(args(), "upgrade")
|
||||
}
|
||||
|
||||
pub fn run(args: Args) -> Result<i32, Error> {
|
||||
let (_db_dir, mut conn) = super::open_conn(&args.db_dir, super::OpenMode::ReadWrite)?;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user