From a0e5625a256fb55e68f1c83ce997e44017e72358 Mon Sep 17 00:00:00 2001 From: fly_1997 Date: Wed, 5 Mar 2025 23:18:09 +0800 Subject: [PATCH] add parameter detection --- src/client/arg_parse.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/client/arg_parse.cpp b/src/client/arg_parse.cpp index cb97054..afe95d2 100644 --- a/src/client/arg_parse.cpp +++ b/src/client/arg_parse.cpp @@ -81,6 +81,8 @@ int ArgParse::InitCmd(int &cmd, int opt) if (optarg) { SetArg(optarg); } + } else { + return -1; } return 0; } @@ -120,11 +122,17 @@ int ArgParse::Init(int argc, char *argv[]) break; } default: { - InitCmd(cmd, opt); + if (InitCmd(cmd, opt) < 0) { + return -1; + } break; } } } + for (int i = optind; i < argc; ++i) { + ArgError("invalid option [" + std::string(argv[i]) + "]."); + return -1; + } if (help) { PrintHelp(); exit(EXIT_SUCCESS); -- 2.33.0