panic on unknown CLI arguments

Currently silently ignores which is not helpful ...
This commit is contained in:
Ken Sedgwick
2025-02-05 10:43:21 -08:00
parent 201cfb2db1
commit 480f98eda4
7 changed files with 113 additions and 7 deletions

View File

@@ -60,6 +60,19 @@ pub async fn android_main(app: AndroidApp) {
setup_chrome(ctx, &notedeck.args(), notedeck.theme());
let damus = Damus::new(&mut notedeck.app_context(), &app_args);
// ensure we recognized all the arguments
let completely_unrecognized: Vec<String> = notedeck
.unrecognized_args()
.intersection(damus.unrecognized_args())
.cloned()
.collect();
assert!(
completely_unrecognized.is_empty(),
"unrecognized args: {:?}",
completely_unrecognized
);
notedeck.set_app(damus);
Ok(Box::new(notedeck))

View File

@@ -78,6 +78,19 @@ async fn main() {
setup_chrome(ctx, notedeck.args(), notedeck.theme());
let damus = Damus::new(&mut notedeck.app_context(), &args);
// ensure we recognized all the arguments
let completely_unrecognized: Vec<String> = notedeck
.unrecognized_args()
.intersection(&damus.unrecognized_args())
.cloned()
.collect();
assert!(
completely_unrecognized.is_empty(),
"unrecognized args: {:?}",
completely_unrecognized
);
// TODO: move "chrome" frame over Damus app somehow
notedeck.set_app(damus);
@@ -173,9 +186,21 @@ mod tests {
let ctx = egui::Context::default();
let mut notedeck = Notedeck::new(&ctx, &tmpdir, &args);
let unrecognized_args = notedeck.unrecognized_args().clone();
let mut app_ctx = notedeck.app_context();
let app = Damus::new(&mut app_ctx, &args);
// ensure we recognized all the arguments
let completely_unrecognized: Vec<String> = unrecognized_args
.intersection(app.unrecognized_args())
.cloned()
.collect();
assert!(
completely_unrecognized.is_empty(),
"unrecognized args: {:?}",
completely_unrecognized
);
assert_eq!(app.columns(app_ctx.accounts).columns().len(), 2);
let tl1 = app
@@ -200,4 +225,39 @@ mod tests {
rmrf(tmpdir);
}
#[tokio::test]
async fn test_unknown_args() {
let tmpdir = create_tmp_dir();
let npub = "npub1xtscya34g58tk0z605fvr788k263gsu6cy9x0mhnm87echrgufzsevkk5s";
let args: Vec<String> = [
"--testrunner",
"--no-keystore",
"--unknown-arg", // <-- UNKNOWN
"--pub",
npub,
"-c",
"notifications",
"-c",
"contacts",
]
.iter()
.map(|s| s.to_string())
.collect();
let ctx = egui::Context::default();
let mut notedeck = Notedeck::new(&ctx, &tmpdir, &args);
let mut app_ctx = notedeck.app_context();
let app = Damus::new(&mut app_ctx, &args);
// ensure we recognized all the arguments
let completely_unrecognized: Vec<String> = notedeck
.unrecognized_args()
.intersection(app.unrecognized_args())
.cloned()
.collect();
assert_eq!(completely_unrecognized, ["--unknown-arg"]);
rmrf(tmpdir);
}
}

View File

@@ -33,6 +33,11 @@ impl PreviewRunner {
let ctx = &cc.egui_ctx;
let mut notedeck = Notedeck::new(ctx, &base_path, &args);
assert!(
notedeck.unrecognized_args().is_empty(),
"unrecognized args: {:?}",
notedeck.unrecognized_args()
);
setup_chrome(ctx, notedeck.args(), notedeck.theme());
notedeck.set_app(PreviewApp::new(preview));