Skip to content

Commit fa5f639

Browse files
authored
Print the help when -h or --help is encountered (#264)
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.
1 parent 77d8abd commit fa5f639

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

main.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1719,6 +1719,14 @@ int parse(const int argc, char **argv) {
17191719
};
17201720

17211721
auto args = cli::make_args(argc, argv);
1722+
1723+
// Check if any -h or --help argument was requested, if so insert the help subcommand before any
1724+
// arguments, this will ensure the correct help gets printed automatically.
1725+
bool help_requested = std::find(args.begin(), args.end(), "--help") != args.end()
1726+
|| std::find(args.begin(), args.end(), "-h") != args.end();
1727+
if (help_requested) {
1728+
args.insert(args.begin(), "help");
1729+
}
17221730
if (args.empty()) {
17231731
usage();
17241732
return 0;

0 commit comments

Comments
 (0)