Merge "libutil: fix args assert being thrown on Darwin in nix-eval-jobs" into main

This commit is contained in:
jade 2024-05-31 18:57:13 +00:00 committed by Gerrit Code Review
commit a75d7a5777
3 changed files with 12 additions and 1 deletions

View file

@ -64,7 +64,7 @@ RootArgs & Args::getRoot()
while (p->parent)
p = p->parent;
auto * res = dynamic_cast<RootArgs *>(p);
auto res = p->asRootArgs();
assert(res);
return *res;
}

View file

@ -244,6 +244,13 @@ protected:
*/
virtual void initialFlagsProcessed() {}
/**
* Returns this Args as a RootArgs if it is one, or \ref std::nullopt otherwise.
*/
virtual std::optional<std::reference_wrapper<RootArgs>> asRootArgs() {
return std::nullopt;
}
public:
void addFlag(Flag && flag);

View file

@ -65,6 +65,10 @@ protected:
*/
std::set<ExperimentalFeature> flagExperimentalFeatures;
virtual std::optional<std::reference_wrapper<RootArgs>> asRootArgs() override {
return *this;
}
private:
std::optional<std::string> needsCompletion(std::string_view s);