misc

Unnamed repository; edit this file 'description' to name the repository.
git clone git://git.alexwennerberg.com/misc
Log | Files | Refs | README | LICENSE

commit 395314260cccb55426719dfd8b73e8e2e25e2016
parent c2b8b5bdc86e97634e9492bfd2fb2cc4a7ff0293
Author: alex wennerberg <alex@alexwennerberg.com>
Date:   Sat, 26 Feb 2022 11:47:18 -0800

Add windows support

Diffstat:
Marg.rs | 15+++++++--------
1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/arg.rs b/arg.rs @@ -27,8 +27,6 @@ // 2. No use of macros // // Copy/paste this code and you have a CLI! No library needed! -// -// Only works on unix-like system right now. Windows support TBD use std::env; use std::ffi::OsString; @@ -85,16 +83,17 @@ impl Args { let mut out = Self::default(); let mut args = env::args_os().skip(1); while let Some(arg) = args.next() { - let bytes = arg.as_os_str().as_bytes(); - if bytes[0] != b'-' { + let s = arg.to_string_lossy(); + let mut ch_iter = s.chars(); + if ch_iter.next() != Some('-') { out.positional.push(arg); continue; } - bytes[1..].iter().for_each(|m| match m { + ch_iter.for_each(|m| match m { // Edit these lines // - b'a' => out.a = true, - b'f' => out.f = parse_os_arg(args.next()), - b'b' => out.b = parse_arg(args.next()), + 'a' => out.a = true, + 'f' => out.f = parse_os_arg(args.next()), + 'b' => out.b = parse_arg(args.next()), // Stop editing // _ => usage(), })