From 1a8267c3a55a5043f41df9b4c0646c300112c6ee Mon Sep 17 00:00:00 2001 From: marcelarie Date: Tue, 15 Oct 2024 01:08:25 +0200 Subject: [PATCH] feat: Add no comments flag and help message --- README.md | 9 +++--- src/command/arguments.rs | 60 ++++++++++++++++++++++++++++++++-------- src/main.rs | 8 ++++-- 3 files changed, 59 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 970005f..a8311ef 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,7 @@ TODO: - [x] Write them to a file - [x] Single time - [ ] Use nushell env + - [x] Add no comments flag - [ ] Add a command to source the file - [ ] Handle multiple files in a directory @@ -37,7 +38,8 @@ manually or use the Nushell environment. If using the environment method, the file will regenerate at the start of each shell session. **Unnecessary diagram:** - not that complex but I always wanted to try this out. +Not that complex but I always wanted to try this out. + ```mermaid --- config: @@ -56,13 +58,10 @@ graph TD D --> I[Comment Out Invalid Aliases] I --> J[Include Parsing Error Information] ``` - - - ## Usage -current implementation: +Current implementation: ```bash nu-alias-converter .bash_aliases # will generate a alias.nu file in the same directory diff --git a/src/command/arguments.rs b/src/command/arguments.rs index 7e937d4..bcf80f0 100644 --- a/src/command/arguments.rs +++ b/src/command/arguments.rs @@ -4,11 +4,10 @@ pub struct CliArgs { pub debug_mode: bool, } -pub struct GatheredArgs { +struct GatheredArgs { file_path: Option, no_comments: bool, debug_mode: bool, - #[allow(unused)] arguments: Vec, #[allow(unused)] remaining_args: Vec, @@ -41,7 +40,24 @@ impl CliArgs { debug_mode = true; Some(arg.to_string()) } - _ => None, + "--help" | "-h" => Some(arg.to_string()), + _ => { + let chars = arg.chars().collect::>(); + for (index, c) in chars.iter().enumerate() { + if c == &'-' { + println!("Invalid flag: {}", arg); + println!("Use -h for help"); + std::process::exit(1); + } + let flag = format!("-{}", c); + let value = + arg.chars().skip(index + 1).collect::(); + arguments.push(flag); + arguments.push(value); + break; + } + None + } }; if let Some(flag_value) = flag_value { @@ -58,16 +74,38 @@ impl CliArgs { } } + fn print_help() { + println!( + "Usage: {} [options]