1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-25 06:31:14 +02:00

Refactor, dedup nix formatter attribute methods

This commit is contained in:
Robert Hensing 2025-04-28 15:08:15 +02:00 committed by Jeremy Fleischman
parent ba6b617e75
commit e14346c7da
No known key found for this signature in database

View file

@ -27,7 +27,21 @@ struct CmdFormatter : NixMultiCommand
static auto rCmdFormatter = registerCommand<CmdFormatter>("formatter");
struct CmdFormatterRun : SourceExprCommand, MixJSON
/** Common implementation bits for the `nix formatter` subcommands. */
struct MixFormatter : SourceExprCommand
{
Strings getDefaultFlakeAttrPaths() override
{
return Strings{"formatter." + settings.thisSystem.get()};
}
Strings getDefaultFlakeAttrPathPrefixes() override
{
return Strings{};
}
};
struct CmdFormatterRun : MixFormatter, MixJSON
{
std::vector<std::string> args;
@ -53,16 +67,6 @@ struct CmdFormatterRun : SourceExprCommand, MixJSON
return catSecondary;
}
Strings getDefaultFlakeAttrPaths() override
{
return Strings{"formatter." + settings.thisSystem.get()};
}
Strings getDefaultFlakeAttrPathPrefixes() override
{
return Strings{};
}
void run(ref<Store> store) override
{
auto evalState = getEvalState();
@ -89,7 +93,7 @@ struct CmdFormatterRun : SourceExprCommand, MixJSON
static auto rFormatterRun = registerCommand2<CmdFormatterRun>({"formatter", "run"});
struct CmdFormatterBuild : SourceExprCommand
struct CmdFormatterBuild : MixFormatter
{
Path outLink = "result";
@ -128,16 +132,6 @@ struct CmdFormatterBuild : SourceExprCommand
return catSecondary;
}
Strings getDefaultFlakeAttrPaths() override
{
return Strings{"formatter." + settings.thisSystem.get()};
}
Strings getDefaultFlakeAttrPathPrefixes() override
{
return Strings{};
}
void run(ref<Store> store) override
{
auto evalState = getEvalState();