From c84e23f95bc52121bf639c736c3c27ec6d11f8b2 Mon Sep 17 00:00:00 2001 From: Valerie Wolfe Date: Wed, 5 Jun 2024 09:57:29 -0400 Subject: [PATCH] added quote flag --- path-convert/Cargo.toml | 2 +- path-convert/src/main.rs | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/path-convert/Cargo.toml b/path-convert/Cargo.toml index 87f8583..a1dd639 100644 --- a/path-convert/Cargo.toml +++ b/path-convert/Cargo.toml @@ -4,7 +4,7 @@ version = "0.0.2" edition = "2021" [dependencies] -pico-args = "0.5.0" +pico-args = { version = "0.5.0", features = [ "combined-flags" ] } [profile.release] opt-level = 's' diff --git a/path-convert/src/main.rs b/path-convert/src/main.rs index 371de80..ad9b635 100644 --- a/path-convert/src/main.rs +++ b/path-convert/src/main.rs @@ -4,9 +4,18 @@ use pico_args::Arguments; const DRIVE: &str = "/mnt/c/"; +const QUOTED: [&str;2] = [ "-q", "--quotes" ]; + pub fn main() { let mut args = Arguments::from_env(); + // handle quote flag + let quotes: &str = + if args.contains(QUOTED) { + if args.contains(QUOTED) { "\"" } // -qq -> "..." (output with double quotes) + else { "'" } // -q -> '...' (output with single quotes) + } else { "" }; // _ -> ... (output with no quotes) + loop { let next = args.subcommand().unwrap(); if let Some(arg) = next { @@ -28,7 +37,7 @@ pub fn main() { output = output.replace("/", "\\"); // emit to stdout - println!("{output}"); + println!("{quotes}{output}{quotes}"); } else { break; }