From 9d5204dff839f9cdf109d0e83eb6d46e2609312e Mon Sep 17 00:00:00 2001 From: Thilina Ratnayaka Date: Tue, 29 Oct 2024 23:12:52 -0400 Subject: [PATCH] Fix a bug in parsing occa cli options --- src/occa/internal/utils/cli.cpp | 12 ++++++++++-- src/occa/internal/utils/cli.hpp | 3 +++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/occa/internal/utils/cli.cpp b/src/occa/internal/utils/cli.cpp index dd332ba67..2f0de8306 100644 --- a/src/occa/internal/utils/cli.cpp +++ b/src/occa/internal/utils/cli.cpp @@ -405,6 +405,7 @@ namespace occa { } occa::json parser::parseArgs(const strVector &args_, + const std::vector *commands, const bool supressErrors) { strVector args = splitShortOptionArgs(args_); const int argc = (int) args.size(); @@ -445,7 +446,14 @@ namespace occa { // No option if (!opt) { - checkOptions = (arg == "=="); + if (commands != nullptr) { + for (auto cmd : *commands) { + if (arg == cmd.name) { + checkOptions = 0; + break; + } + } + } jArguments += arg; continue; } @@ -779,7 +787,7 @@ namespace occa { const bool hasCommands = commands.size(); - json parsedArgs = parseArgs(shellArgs, supressErrors); + json parsedArgs = parseArgs(shellArgs, &commands, supressErrors); lastCommandArgs = parsedArgs; json &jArguments = parsedArgs["arguments"]; diff --git a/src/occa/internal/utils/cli.hpp b/src/occa/internal/utils/cli.hpp index 0ead626ad..e9c15edca 100644 --- a/src/occa/internal/utils/cli.hpp +++ b/src/occa/internal/utils/cli.hpp @@ -120,6 +120,8 @@ namespace occa { }; //================================== + class command; + //---[ Parser ]--------------------- class parser : public printable { public: @@ -157,6 +159,7 @@ namespace occa { occa::json parseArgs(const int argc, const char **argv); occa::json parseArgs(const strVector &args_, + const std::vector *commands = nullptr, const bool supressErrors = false); bool hasCustomHelpOption();