diff options
author | jakobst1n <jakob.stendahl@outlook.com> | 2024-06-09 16:14:51 +0200 |
---|---|---|
committer | jakobst1n <jakob.stendahl@outlook.com> | 2024-06-09 16:14:51 +0200 |
commit | 12d98b326369d8af56d690a86ce82f862026a701 (patch) | |
tree | 4468d7752766c31f11b067c91e78b119601ee09f | |
parent | 0197c7069d9c814650cea8caf14731a39b8eca89 (diff) | |
download | textgraph-12d98b326369d8af56d690a86ce82f862026a701.tar.gz textgraph-12d98b326369d8af56d690a86ce82f862026a701.zip |
Fix parsing of positional arguments
-rw-r--r-- | src/parseopts.rs | 14 |
1 files changed, 13 insertions, 1 deletions
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; } |