From 25bc28e331cab46633a1b933e0093fa450c4ace1 Mon Sep 17 00:00:00 2001 From: Haobo Gu Date: Mon, 28 Oct 2024 10:59:54 +0800 Subject: [PATCH 1/2] Add support for -h/--help arg Signed-off-by: Haobo Gu --- CHANGELOG.md | 4 ++++ src/main.rs | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 63641c1..cbc27d9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] +- [#102] Add support for -h/--help arg and no arg + +[#102]: https://github.com/knurling-rs/flip-link/pull/102 + ## [v0.1.9] - 2024-08-14 - [#96] Add support for @file args diff --git a/src/main.rs b/src/main.rs index eac095d..5f8abbb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -29,6 +29,24 @@ fn notmain() -> Result { // NOTE `skip` the name/path of the binary (first argument) let raw_args = env::args().skip(1).collect::>(); + // If there's no argument provided, print the help message + if matches!( + raw_args + .iter() + .map(|s| s.as_str()) + .collect::>() + .as_slice(), + [] | ["--help"] | ["-h"] + ) { + eprintln!( + "flip-link: adds zero-cost stack overflow protection to your \ + embedded programs\nYou should not use flip-link directly from \ + command line, use flip-link as your default linker instead. \n\n\ + For detailed usage, check https://github.com/knurling-rs/flip-link" + ); + return Ok(0); + } + { let exit_status = linking::link_normally(&raw_args)?; if !exit_status.success() { From 5e514c30aefea37adac37b5ea24b3862043c361d Mon Sep 17 00:00:00 2001 From: Johann Hemmann Date: Mon, 28 Oct 2024 17:32:59 +0100 Subject: [PATCH 2/2] Simplify condition --- src/main.rs | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/main.rs b/src/main.rs index 5f8abbb..82bac6a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -30,14 +30,7 @@ fn notmain() -> Result { let raw_args = env::args().skip(1).collect::>(); // If there's no argument provided, print the help message - if matches!( - raw_args - .iter() - .map(|s| s.as_str()) - .collect::>() - .as_slice(), - [] | ["--help"] | ["-h"] - ) { + if let None | Some("--help" | "-h") = raw_args.first().map(String::as_str) { eprintln!( "flip-link: adds zero-cost stack overflow protection to your \ embedded programs\nYou should not use flip-link directly from \