From 045e13fd206770c70b7a570d266751f94bb2c296 Mon Sep 17 00:00:00 2001 From: Ivor Wanders Date: Mon, 18 Aug 2025 18:55:28 -0400 Subject: [PATCH] Print the help when -h or --help is encountered This inserts the 'help' command at the start of the argument list in case the '-h' or '--help' argument is encountered anywhere on the commandline. --- main.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/main.cpp b/main.cpp index 917c415..0059593 100644 --- a/main.cpp +++ b/main.cpp @@ -1719,6 +1719,14 @@ int parse(const int argc, char **argv) { }; auto args = cli::make_args(argc, argv); + + // Check if any -h or --help argument was requested, if so insert the help subcommand before any + // arguments, this will ensure the correct help gets printed automatically. + bool help_requested = std::find(args.begin(), args.end(), "--help") != args.end() + || std::find(args.begin(), args.end(), "-h") != args.end(); + if (help_requested) { + args.insert(args.begin(), "help"); + } if (args.empty()) { usage(); return 0;