Skip to content

Commit ad07be0

Browse files
authored
Merge pull request #14665 from vinayakankugoyal/path
Use std::filesystem::path in libmain.
2 parents 35492fe + 16f218b commit ad07be0

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

src/libmain/plugin.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,30 +10,30 @@
1010

1111
namespace nix {
1212

13-
struct PluginFilesSetting : public BaseSetting<Paths>
13+
struct PluginFilesSetting : public BaseSetting<std::list<std::filesystem::path>>
1414
{
1515
bool pluginsLoaded = false;
1616

1717
PluginFilesSetting(
1818
Config * options,
19-
const Paths & def,
19+
const std::list<std::filesystem::path> & def,
2020
const std::string & name,
2121
const std::string & description,
2222
const StringSet & aliases = {})
23-
: BaseSetting<Paths>(def, true, name, description, aliases)
23+
: BaseSetting<std::list<std::filesystem::path>>(def, true, name, description, aliases)
2424
{
2525
options->addSetting(this);
2626
}
2727

28-
Paths parse(const std::string & str) const override;
28+
std::list<std::filesystem::path> parse(const std::string & str) const override;
2929
};
3030

31-
Paths PluginFilesSetting::parse(const std::string & str) const
31+
std::list<std::filesystem::path> PluginFilesSetting::parse(const std::string & str) const
3232
{
3333
if (pluginsLoaded)
3434
throw UsageError(
3535
"plugin-files set after plugins were loaded, you may need to move the flag before the subcommand");
36-
return BaseSetting<Paths>::parse(str);
36+
return BaseSetting<std::list<std::filesystem::path>>::parse(str);
3737
}
3838

3939
struct PluginSettings : Config

src/libutil/configuration.cc

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,12 +330,27 @@ void BaseSetting<bool>::convertToArg(Args & args, const std::string & category)
330330
});
331331
}
332332

333+
template<>
334+
std::list<std::filesystem::path> BaseSetting<std::list<std::filesystem::path>>::parse(const std::string & str) const
335+
{
336+
auto tokens = tokenizeString<std::list<std::string>>(str);
337+
return {tokens.begin(), tokens.end()};
338+
}
339+
333340
template<>
334341
Strings BaseSetting<Strings>::parse(const std::string & str) const
335342
{
336343
return tokenizeString<Strings>(str);
337344
}
338345

346+
template<>
347+
void BaseSetting<std::list<std::filesystem::path>>::appendOrSet(std::list<std::filesystem::path> newValue, bool append)
348+
{
349+
if (!append)
350+
value.clear();
351+
value.insert(value.end(), std::make_move_iterator(newValue.begin()), std::make_move_iterator(newValue.end()));
352+
}
353+
339354
template<>
340355
void BaseSetting<Strings>::appendOrSet(Strings newValue, bool append)
341356
{
@@ -344,6 +359,14 @@ void BaseSetting<Strings>::appendOrSet(Strings newValue, bool append)
344359
value.insert(value.end(), std::make_move_iterator(newValue.begin()), std::make_move_iterator(newValue.end()));
345360
}
346361

362+
template<>
363+
std::string BaseSetting<std::list<std::filesystem::path>>::to_string() const
364+
{
365+
return concatStringsSep(" ", value | std::views::transform([](const auto & p) {
366+
return p.string();
367+
}) | std::ranges::to<std::list<std::string>>());
368+
}
369+
347370
template<>
348371
std::string BaseSetting<Strings>::to_string() const
349372
{
@@ -477,6 +500,7 @@ template class BaseSetting<long long>;
477500
template class BaseSetting<unsigned long long>;
478501
template class BaseSetting<bool>;
479502
template class BaseSetting<std::string>;
503+
template class BaseSetting<std::list<std::filesystem::path>>;
480504
template class BaseSetting<Strings>;
481505
template class BaseSetting<StringSet>;
482506
template class BaseSetting<StringMap>;

0 commit comments

Comments
 (0)