panic on unknown CLI arguments
Currently silently ignores which is not helpful ...
This commit is contained in:
@@ -7,6 +7,7 @@ use egui::ThemePreference;
|
||||
use enostr::RelayPool;
|
||||
use nostrdb::{Config, Ndb, Transaction};
|
||||
use std::cell::RefCell;
|
||||
use std::collections::BTreeSet;
|
||||
use std::path::Path;
|
||||
use std::rc::Rc;
|
||||
use tracing::{error, info};
|
||||
@@ -29,6 +30,7 @@ pub struct Notedeck {
|
||||
app: Option<Rc<RefCell<dyn App>>>,
|
||||
zoom: ZoomHandler,
|
||||
app_size: AppSizeHandler,
|
||||
unrecognized_args: BTreeSet<String>,
|
||||
}
|
||||
|
||||
fn margin_top(narrow: bool) -> f32 {
|
||||
@@ -106,7 +108,9 @@ impl Notedeck {
|
||||
#[cfg(feature = "profiling")]
|
||||
setup_profiling();
|
||||
|
||||
let parsed_args = Args::parse(args);
|
||||
// Skip the first argument, which is the program name.
|
||||
let args_to_parse: Vec<String> = args[1..].to_vec();
|
||||
let (parsed_args, unrecognized_args) = Args::parse(&args_to_parse);
|
||||
|
||||
let data_path = parsed_args
|
||||
.datapath
|
||||
@@ -203,6 +207,7 @@ impl Notedeck {
|
||||
app: None,
|
||||
zoom,
|
||||
app_size,
|
||||
unrecognized_args,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -236,4 +241,8 @@ impl Notedeck {
|
||||
pub fn theme(&self) -> ThemePreference {
|
||||
self.theme.load()
|
||||
}
|
||||
|
||||
pub fn unrecognized_args(&self) -> &BTreeSet<String> {
|
||||
&self.unrecognized_args
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
use std::collections::BTreeSet;
|
||||
|
||||
use enostr::{Keypair, Pubkey, SecretKey};
|
||||
use tracing::error;
|
||||
|
||||
@@ -18,7 +20,9 @@ pub struct Args {
|
||||
}
|
||||
|
||||
impl Args {
|
||||
pub fn parse(args: &[String]) -> Self {
|
||||
// parse arguments, return set of unrecognized args
|
||||
pub fn parse(args: &[String]) -> (Self, BTreeSet<String>) {
|
||||
let mut unrecognized_args = BTreeSet::new();
|
||||
let mut res = Args {
|
||||
relays: vec![],
|
||||
is_mobile: None,
|
||||
@@ -112,11 +116,13 @@ impl Args {
|
||||
res.use_keystore = false;
|
||||
} else if arg == "--relay-debug" {
|
||||
res.relay_debug = true;
|
||||
} else {
|
||||
unrecognized_args.insert(arg.clone());
|
||||
}
|
||||
|
||||
i += 1;
|
||||
}
|
||||
|
||||
res
|
||||
(res, unrecognized_args)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user