fix: use data_dir from config.toml if present

fixes: https://todo.sr.ht/~gheartsfield/nostr-rs-relay/64
This commit is contained in:
Greg Heartsfield 2023-01-16 17:21:12 -06:00
parent cf3e67500f
commit 585fdd3884
3 changed files with 6 additions and 8 deletions

View File

@ -24,7 +24,7 @@ description = "A newly created nostr-rs-relay.\n\nCustomize this with your own i
# Directory for SQLite files. Defaults to the current directory. Can # Directory for SQLite files. Defaults to the current directory. Can
# also be specified (and overriden) with the "--db dirname" command # also be specified (and overriden) with the "--db dirname" command
# line option. # line option.
data_directory = "." #data_directory = "."
# Use an in-memory database instead of 'nostr.db'. # Use an in-memory database instead of 'nostr.db'.

View File

@ -7,8 +7,7 @@ pub struct CLIArgs {
short, short,
long, long,
help = "Use the <directory> as the location of the database", help = "Use the <directory> as the location of the database",
default_value = ".", required = false,
required = false
)] )]
pub db: String, pub db: Option<String>,
} }

View File

@ -31,13 +31,12 @@ fn main() {
let args = CLIArgs::parse(); let args = CLIArgs::parse();
// get database directory from args // get database directory from args
let db_dir = args.db; let db_dir_arg = args.db;
// update with database location // update with database location from args, if provided
if db_dir.len() > 0 { if let Some(db_dir) = db_dir_arg {
settings.database.data_directory = db_dir; settings.database.data_directory = db_dir;
} }
let (_, ctrl_rx): (MpscSender<()>, MpscReceiver<()>) = syncmpsc::channel(); let (_, ctrl_rx): (MpscSender<()>, MpscReceiver<()>) = syncmpsc::channel();
// run this in a new thread // run this in a new thread
let handle = thread::spawn(|| { let handle = thread::spawn(|| {