From 16f218b37c0152cf606cfd59337872dd2875738c Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Wed, 26 Nov 2025 21:13:46 +0000 Subject: [PATCH] Use std::filesystem::path in libmain. --- src/libmain/plugin.cc | 12 ++++++------ src/libutil/configuration.cc | 24 ++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/src/libmain/plugin.cc b/src/libmain/plugin.cc index 321fd6a15..4755ba24b 100644 --- a/src/libmain/plugin.cc +++ b/src/libmain/plugin.cc @@ -10,30 +10,30 @@ namespace nix { -struct PluginFilesSetting : public BaseSetting +struct PluginFilesSetting : public BaseSetting> { bool pluginsLoaded = false; PluginFilesSetting( Config * options, - const Paths & def, + const std::list & def, const std::string & name, const std::string & description, const StringSet & aliases = {}) - : BaseSetting(def, true, name, description, aliases) + : BaseSetting>(def, true, name, description, aliases) { options->addSetting(this); } - Paths parse(const std::string & str) const override; + std::list parse(const std::string & str) const override; }; -Paths PluginFilesSetting::parse(const std::string & str) const +std::list PluginFilesSetting::parse(const std::string & str) const { if (pluginsLoaded) throw UsageError( "plugin-files set after plugins were loaded, you may need to move the flag before the subcommand"); - return BaseSetting::parse(str); + return BaseSetting>::parse(str); } struct PluginSettings : Config diff --git a/src/libutil/configuration.cc b/src/libutil/configuration.cc index ee24bb4e5..832099dab 100644 --- a/src/libutil/configuration.cc +++ b/src/libutil/configuration.cc @@ -330,12 +330,27 @@ void BaseSetting::convertToArg(Args & args, const std::string & category) }); } +template<> +std::list BaseSetting>::parse(const std::string & str) const +{ + auto tokens = tokenizeString>(str); + return {tokens.begin(), tokens.end()}; +} + template<> Strings BaseSetting::parse(const std::string & str) const { return tokenizeString(str); } +template<> +void BaseSetting>::appendOrSet(std::list newValue, bool append) +{ + if (!append) + value.clear(); + value.insert(value.end(), std::make_move_iterator(newValue.begin()), std::make_move_iterator(newValue.end())); +} + template<> void BaseSetting::appendOrSet(Strings newValue, bool append) { @@ -344,6 +359,14 @@ void BaseSetting::appendOrSet(Strings newValue, bool append) value.insert(value.end(), std::make_move_iterator(newValue.begin()), std::make_move_iterator(newValue.end())); } +template<> +std::string BaseSetting>::to_string() const +{ + return concatStringsSep(" ", value | std::views::transform([](const auto & p) { + return p.string(); + }) | std::ranges::to>()); +} + template<> std::string BaseSetting::to_string() const { @@ -477,6 +500,7 @@ template class BaseSetting; template class BaseSetting; template class BaseSetting; template class BaseSetting; +template class BaseSetting>; template class BaseSetting; template class BaseSetting; template class BaseSetting;