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) while (p->parent)
p = p->parent; p = p->parent;
auto * res = dynamic_cast<RootArgs *>(p); auto res = p->asRootArgs();
assert(res); assert(res);
return *res; return *res;
} }

View file

@ -244,6 +244,13 @@ protected:
*/ */
virtual void initialFlagsProcessed() {} 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: public:
void addFlag(Flag && flag); void addFlag(Flag && flag);

View file

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