add drop db argument
This commit is contained in:
parent
568fcab859
commit
6b17222076
@ -2,7 +2,7 @@ use std::{
|
||||
collections::HashSet,
|
||||
env,
|
||||
fs::File,
|
||||
io,
|
||||
io::{self, stdin, stdout, Write},
|
||||
process::exit,
|
||||
sync::{atomic::AtomicBool, Arc, Mutex},
|
||||
thread,
|
||||
@ -14,6 +14,7 @@ use actix_web::{
|
||||
};
|
||||
use actix_web_grants::authorities::AttachAuthorities;
|
||||
use actix_web_httpauth::{extractors::bearer::BearerAuth, middleware::HttpAuthentication};
|
||||
use sqlx::{migrate::MigrateDatabase, Sqlite};
|
||||
|
||||
#[cfg(all(not(debug_assertions), feature = "embed_frontend"))]
|
||||
use actix_web_static_files::ResourceFiles;
|
||||
@ -35,6 +36,7 @@ use ffplayout::{
|
||||
utils::{
|
||||
args_parse::run_args,
|
||||
config::get_config,
|
||||
db_path,
|
||||
logging::{init_logging, MailQueue},
|
||||
playlist::generate_playlist,
|
||||
},
|
||||
@ -289,6 +291,24 @@ async fn main() -> std::io::Result<()> {
|
||||
playlist,
|
||||
Arc::new(AtomicBool::new(false)),
|
||||
);
|
||||
} else if ARGS.drop_db {
|
||||
let mut drop_answer = String::new();
|
||||
|
||||
print!("Drop Database [Y/n]: ");
|
||||
stdout().flush().unwrap();
|
||||
|
||||
stdin()
|
||||
.read_line(&mut drop_answer)
|
||||
.expect("Did not enter a yes or no?");
|
||||
|
||||
let drop = drop_answer.trim().to_lowercase().starts_with('y');
|
||||
|
||||
if drop {
|
||||
match Sqlite::drop_database(db_path().unwrap()).await {
|
||||
Ok(_) => info!("Successfully dropped DB"),
|
||||
Err(e) => error!("{e}"),
|
||||
};
|
||||
}
|
||||
} else if !ARGS.init {
|
||||
error!("Run ffplayout with parameters! Run ffplayout -h for more information.");
|
||||
}
|
||||
|
@ -35,9 +35,16 @@ pub struct Args {
|
||||
#[clap(short, long, help = "Add a global admin user")]
|
||||
pub add: bool,
|
||||
|
||||
#[clap(long, env, help = "path to database file")]
|
||||
#[clap(long, env, help = "Path to database file")]
|
||||
pub db: Option<PathBuf>,
|
||||
|
||||
#[clap(
|
||||
long,
|
||||
env,
|
||||
help = "Drop database. WARNING: this will delete all configurations!"
|
||||
)]
|
||||
pub drop_db: bool,
|
||||
|
||||
#[clap(
|
||||
short,
|
||||
long,
|
||||
|
Loading…
Reference in New Issue
Block a user