diff options
author | John Ericson <John.Ericson@Obsidian.Systems> | 2023-01-11 01:51:14 -0500 |
---|---|---|
committer | John Ericson <John.Ericson@Obsidian.Systems> | 2023-01-11 18:54:50 -0500 |
commit | a8f45b5e5a42daa9bdee640255464d4dbb431352 (patch) | |
tree | 2acc2850c93f2edd4327918dd4886bbbb138b6e0 /src/libstore/outputs-spec.cc | |
parent | a3ba80357d3a792eb1690011f253c64840c6ae72 (diff) |
Improve `OutputsSpec` slightly
A few little changes preparing for the rest.
Diffstat (limited to 'src/libstore/outputs-spec.cc')
-rw-r--r-- | src/libstore/outputs-spec.cc | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/src/libstore/outputs-spec.cc b/src/libstore/outputs-spec.cc index 76779d193..b5ea7e325 100644 --- a/src/libstore/outputs-spec.cc +++ b/src/libstore/outputs-spec.cc @@ -1,3 +1,4 @@ +#include "util.hh" #include "outputs-spec.hh" #include "nlohmann/json.hpp" @@ -5,7 +6,7 @@ namespace nix { -std::pair<std::string, OutputsSpec> parseOutputsSpec(const std::string & s) +std::pair<std::string, OutputsSpec> OutputsSpec::parse(std::string s) { static std::regex regex(R"((.*)\^((\*)|([a-z]+(,[a-z]+)*)))"); @@ -19,18 +20,19 @@ std::pair<std::string, OutputsSpec> parseOutputsSpec(const std::string & s) return {match[1], tokenizeString<OutputNames>(match[4].str(), ",")}; } -std::string printOutputsSpec(const OutputsSpec & outputsSpec) +std::string OutputsSpec::to_string() const { - if (std::get_if<DefaultOutputs>(&outputsSpec)) - return ""; - - if (std::get_if<AllOutputs>(&outputsSpec)) - return "^*"; - - if (auto outputNames = std::get_if<OutputNames>(&outputsSpec)) - return "^" + concatStringsSep(",", *outputNames); - - assert(false); + return std::visit(overloaded { + [&](const OutputsSpec::Default &) -> std::string { + return ""; + }, + [&](const OutputsSpec::All &) -> std::string { + return "*"; + }, + [&](const OutputsSpec::Names & outputNames) -> std::string { + return "^" + concatStringsSep(",", outputNames); + }, + }, raw()); } void to_json(nlohmann::json & json, const OutputsSpec & outputsSpec) |