mirror of
https://github.com/NixOS/nix
synced 2025-07-07 10:11:47 +02:00
profile: extract getNameFromElement
This commit is contained in:
parent
d83008c3a7
commit
d28a240aa6
1 changed files with 11 additions and 6 deletions
|
@ -101,6 +101,15 @@ struct ProfileElement
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
std::string getNameFromElement(const ProfileElement & element)
|
||||||
|
{
|
||||||
|
std::optional<std::string> result = std::nullopt;
|
||||||
|
if (element.source) {
|
||||||
|
result = getNameFromURL(parseURL(element.source->to_string()));
|
||||||
|
}
|
||||||
|
return result.value_or(element.identifier());
|
||||||
|
}
|
||||||
|
|
||||||
struct ProfileManifest
|
struct ProfileManifest
|
||||||
{
|
{
|
||||||
using ProfileElementName = std::string;
|
using ProfileElementName = std::string;
|
||||||
|
@ -189,12 +198,8 @@ struct ProfileManifest
|
||||||
|
|
||||||
void addElement(ProfileElement element)
|
void addElement(ProfileElement element)
|
||||||
{
|
{
|
||||||
auto name =
|
auto name = getNameFromElement(element);
|
||||||
element.source
|
addElement(name, std::move(element));
|
||||||
? getNameFromURL(parseURL(element.source->to_string()))
|
|
||||||
: std::nullopt;
|
|
||||||
auto name2 = name ? *name : element.identifier();
|
|
||||||
addElement(name2, std::move(element));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
nlohmann::json toJSON(Store & store) const
|
nlohmann::json toJSON(Store & store) const
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue