1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-28 13:11:00 +01:00

Use std::filesystem::path in libmain.

This commit is contained in:
Ubuntu 2025-11-26 21:13:46 +00:00
parent 35492fe94a
commit 16f218b37c
2 changed files with 30 additions and 6 deletions

View file

@ -10,30 +10,30 @@
namespace nix { namespace nix {
struct PluginFilesSetting : public BaseSetting<Paths> struct PluginFilesSetting : public BaseSetting<std::list<std::filesystem::path>>
{ {
bool pluginsLoaded = false; bool pluginsLoaded = false;
PluginFilesSetting( PluginFilesSetting(
Config * options, Config * options,
const Paths & def, const std::list<std::filesystem::path> & def,
const std::string & name, const std::string & name,
const std::string & description, const std::string & description,
const StringSet & aliases = {}) const StringSet & aliases = {})
: BaseSetting<Paths>(def, true, name, description, aliases) : BaseSetting<std::list<std::filesystem::path>>(def, true, name, description, aliases)
{ {
options->addSetting(this); options->addSetting(this);
} }
Paths parse(const std::string & str) const override; std::list<std::filesystem::path> parse(const std::string & str) const override;
}; };
Paths PluginFilesSetting::parse(const std::string & str) const std::list<std::filesystem::path> PluginFilesSetting::parse(const std::string & str) const
{ {
if (pluginsLoaded) if (pluginsLoaded)
throw UsageError( throw UsageError(
"plugin-files set after plugins were loaded, you may need to move the flag before the subcommand"); "plugin-files set after plugins were loaded, you may need to move the flag before the subcommand");
return BaseSetting<Paths>::parse(str); return BaseSetting<std::list<std::filesystem::path>>::parse(str);
} }
struct PluginSettings : Config struct PluginSettings : Config

View file

@ -330,12 +330,27 @@ void BaseSetting<bool>::convertToArg(Args & args, const std::string & category)
}); });
} }
template<>
std::list<std::filesystem::path> BaseSetting<std::list<std::filesystem::path>>::parse(const std::string & str) const
{
auto tokens = tokenizeString<std::list<std::string>>(str);
return {tokens.begin(), tokens.end()};
}
template<> template<>
Strings BaseSetting<Strings>::parse(const std::string & str) const Strings BaseSetting<Strings>::parse(const std::string & str) const
{ {
return tokenizeString<Strings>(str); return tokenizeString<Strings>(str);
} }
template<>
void BaseSetting<std::list<std::filesystem::path>>::appendOrSet(std::list<std::filesystem::path> newValue, bool append)
{
if (!append)
value.clear();
value.insert(value.end(), std::make_move_iterator(newValue.begin()), std::make_move_iterator(newValue.end()));
}
template<> template<>
void BaseSetting<Strings>::appendOrSet(Strings newValue, bool append) void BaseSetting<Strings>::appendOrSet(Strings newValue, bool append)
{ {
@ -344,6 +359,14 @@ void BaseSetting<Strings>::appendOrSet(Strings newValue, bool append)
value.insert(value.end(), std::make_move_iterator(newValue.begin()), std::make_move_iterator(newValue.end())); value.insert(value.end(), std::make_move_iterator(newValue.begin()), std::make_move_iterator(newValue.end()));
} }
template<>
std::string BaseSetting<std::list<std::filesystem::path>>::to_string() const
{
return concatStringsSep(" ", value | std::views::transform([](const auto & p) {
return p.string();
}) | std::ranges::to<std::list<std::string>>());
}
template<> template<>
std::string BaseSetting<Strings>::to_string() const std::string BaseSetting<Strings>::to_string() const
{ {
@ -477,6 +500,7 @@ template class BaseSetting<long long>;
template class BaseSetting<unsigned long long>; template class BaseSetting<unsigned long long>;
template class BaseSetting<bool>; template class BaseSetting<bool>;
template class BaseSetting<std::string>; template class BaseSetting<std::string>;
template class BaseSetting<std::list<std::filesystem::path>>;
template class BaseSetting<Strings>; template class BaseSetting<Strings>;
template class BaseSetting<StringSet>; template class BaseSetting<StringSet>;
template class BaseSetting<StringMap>; template class BaseSetting<StringMap>;