1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-07-06 21:41:48 +02:00

Also display suggestions for the commands using the eval cache

Make `nix build .#nix-armv8l-linux` work for example
This commit is contained in:
regnat 2022-03-04 09:44:00 +01:00
parent 2405bbbb5e
commit 98e361ad4c
4 changed files with 103 additions and 17 deletions

View file

@ -40,4 +40,62 @@ public:
Suggestions& operator+=(const Suggestions & other);
};
// Either a value of type `T`, or some suggestions
template<typename T>
class OrSuggestions {
public:
using Raw = std::variant<T, Suggestions>;
Raw raw;
T* operator ->()
{
return &**this;
}
T& operator *()
{
if (auto elt = std::get_if<T>(&raw))
return *elt;
throw Error("Invalid access to a failed value");
}
operator bool() const noexcept
{
return std::holds_alternative<T>(raw);
}
OrSuggestions(T t)
: raw(t)
{
}
OrSuggestions()
: raw(Suggestions{})
{
}
static OrSuggestions<T> failed(const Suggestions & s)
{
auto res = OrSuggestions<T>();
res.raw = s;
return res;
}
static OrSuggestions<T> failed()
{
return OrSuggestions<T>::failed(Suggestions{});
}
const Suggestions & get_suggestions()
{
static Suggestions noSuggestions;
if (const auto & suggestions = std::get_if<Suggestions>(&raw))
return *suggestions;
else
return noSuggestions;
}
};
}