misc

Misc scripts and tools
git clone git://git.alexwennerberg.com/misc
Log | Files | Refs | README | LICENSE

commit 3096bd960d34918d02b85fd448b76fa67c6907f0
parent d15d0e0161c94d69db2b8a909be2105200213585
Author: alex wennerberg <alex@alexwennerberg.com>
Date:   Fri, 24 Dec 2021 02:21:17 -0800

Remove nested indentation

Diffstat:
Marg.rs | 46++++++++++++++++++++++++----------------------
1 file changed, 24 insertions(+), 22 deletions(-)

diff --git a/arg.rs b/arg.rs @@ -38,32 +38,34 @@ fn main() { while let Some(arg) = args.next() { let mut iter = arg.chars(); - if iter.next() == Some('-') { - for m in iter { - match m { - 'c' => { - var = Some( - args.next() - .and_then(|a| a.parse().ok()) - .unwrap_or_else(|| usage()), - ); - } - 'a' => { - a_enabled = true; - } - 'b' => { - b_enabled = true; - } - _ => { - usage(); - } - } - } - } else { + if iter.next() != Some('-') { positional = Some(arg); + continue; } + iter.map(|m| match m { + 'c' => { + // I think this is the least worst way to do this + var = Some( + args.next() + .and_then(|a| a.parse().ok()) + .unwrap_or_else(|| usage()), + ); + } + 'a' => { + a_enabled = true; + } + 'b' => { + b_enabled = true; + } + _ => { + usage(); + } + }) + .for_each(std::mem::drop); } + // Check mandatory arguments + // Check values of variables, use to direct behavior if a_enabled { println!("a enabled");