mirror of
https://github.com/NixOS/nix.git
synced 2025-12-05 08:31:00 +01:00
Improve OutputsSpec slightly
A few little changes preparing for the rest.
This commit is contained in:
parent
a3ba80357d
commit
a8f45b5e5a
7 changed files with 46 additions and 32 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue