================
@@ -202,6 +205,42 @@ void ArgList::print(raw_ostream &O) const {
 LLVM_DUMP_METHOD void ArgList::dump() const { print(dbgs()); }
 #endif
 
+StringRef ArgList::getSubcommand(
+    const ArrayRef<OptTable::Command> Commands,
+    std::function<void(ArrayRef<StringRef>)> HandleMultipleSubcommands,
+    std::function<void(ArrayRef<StringRef>)> HandleOtherPositionals) const {
+
+  StringRef SubCommand = {};
+  SmallVector<StringRef, 4> SubCommands;
+  SmallVector<StringRef, 4> OtherPositionals;
+  for (const Arg *A : *this) {
+    bool IsSubCommand = false;
+    if (A->getOption().getKind() == Option::InputClass) {
+      for (const OptTable::Command CMD : Commands) {
+        if (StringRef(CMD.Name) == "TopLevelCommand")
+          continue;
+        if (StringRef(CMD.Name) == A->getValue()) {
+          SubCommands.push_back(A->getValue());
+          IsSubCommand = true;
+        }
+      }
+      if (!IsSubCommand) {
+        OtherPositionals.push_back(A->getValue());
+        IsSubCommand = false;
+      }
----------------
PiJoules wrote:

Is it guaranteed that subcommand names are unique? If so then I think this 
could be:

```
auto MaybeSubCmd = std::find_if(Commands.begin(), Commands.end(), [&](auto CMD){
  return StringRef(CMD.Name) == A->getValue();
});
if (MaybeSubCmd == Commands.end())
  OtherPositionals.push_back(A->getValue());
else
  SubCommands.push_back(A->getValue());
```

https://github.com/llvm/llvm-project/pull/155026
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to