From 12d98b326369d8af56d690a86ce82f862026a701 Mon Sep 17 00:00:00 2001 From: jakobst1n Date: Sun, 9 Jun 2024 16:14:51 +0200 Subject: Fix parsing of positional arguments --- src/parseopts.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/parseopts.rs b/src/parseopts.rs index ee05199..a49d02c 100644 --- a/src/parseopts.rs +++ b/src/parseopts.rs @@ -164,6 +164,8 @@ pub fn parseopts() -> Opts { let mut it = std::env::args(); let progname = it.next().expect("TG1"); + let mut pos_arg = 0; + while let Some(mut arg) = it.next() { if arg.starts_with("--") { arg.remove(0); @@ -197,11 +199,21 @@ pub fn parseopts() -> Opts { } } } + } else { + match pos_arg { + 0 => { + opts.in_file = Some(arg); + }, + _ => { + println!("No positional argument expected at position {} (\"{}\")", pos_arg, arg); + parseopts_panic!(progname); + } + } + pos_arg += 1; } } - opts.in_file = it.next(); return opts; } -- cgit v1.2.3