feat: add --help and --version flags

fixes: https://github.com/scsibug/nostr-rs-relay/issues/42
This commit is contained in:
JesterHodl 2023-01-03 14:51:44 +01:00 committed by Greg Heartsfield
parent 3dd0f2c9c6
commit 0e519f6b77

View File

@ -18,6 +18,18 @@ fn db_from_args(args: &[String]) -> Option<String> {
None None
} }
fn print_version() {
println!("{} v{}", env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION"));
}
fn print_help() {
println!("Usage: nostr-rs-relay [OPTION]...\n");
println!("Options:");
println!(" --help Show this help message and exit");
println!(" --version Show version information and exit");
println!(" --db <directory> Use the <directory> as the location of the database");
}
/// Start running a Nostr relay server. /// Start running a Nostr relay server.
fn main() { fn main() {
// setup tracing // setup tracing
@ -25,6 +37,21 @@ fn main() {
info!("Starting up from main"); info!("Starting up from main");
// get database directory from args // get database directory from args
let args: Vec<String> = env::args().collect(); let args: Vec<String> = env::args().collect();
let help_flag: bool = args.contains(&"--help".to_owned());
// if --help flag was passed, display help and exit
if help_flag {
print_help();
return;
}
let version_flag: bool = args.contains(&"--version".to_owned());
// if --version flag was passed, display version and exit
if version_flag {
print_version();
return;
}
let db_dir: Option<String> = db_from_args(&args); let db_dir: Option<String> = db_from_args(&args);
// configure settings from config.toml // configure settings from config.toml
// replace default settings with those read from config.toml // replace default settings with those read from config.toml