mirror of
https://github.com/NixOS/nix
synced 2025-06-28 22:01:15 +02:00
Refactor, dedup nix formatter attribute methods
This commit is contained in:
parent
ba6b617e75
commit
e14346c7da
1 changed files with 16 additions and 22 deletions
|
@ -27,7 +27,21 @@ struct CmdFormatter : NixMultiCommand
|
||||||
|
|
||||||
static auto rCmdFormatter = registerCommand<CmdFormatter>("formatter");
|
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;
|
std::vector<std::string> args;
|
||||||
|
|
||||||
|
@ -53,16 +67,6 @@ struct CmdFormatterRun : SourceExprCommand, MixJSON
|
||||||
return catSecondary;
|
return catSecondary;
|
||||||
}
|
}
|
||||||
|
|
||||||
Strings getDefaultFlakeAttrPaths() override
|
|
||||||
{
|
|
||||||
return Strings{"formatter." + settings.thisSystem.get()};
|
|
||||||
}
|
|
||||||
|
|
||||||
Strings getDefaultFlakeAttrPathPrefixes() override
|
|
||||||
{
|
|
||||||
return Strings{};
|
|
||||||
}
|
|
||||||
|
|
||||||
void run(ref<Store> store) override
|
void run(ref<Store> store) override
|
||||||
{
|
{
|
||||||
auto evalState = getEvalState();
|
auto evalState = getEvalState();
|
||||||
|
@ -89,7 +93,7 @@ struct CmdFormatterRun : SourceExprCommand, MixJSON
|
||||||
|
|
||||||
static auto rFormatterRun = registerCommand2<CmdFormatterRun>({"formatter", "run"});
|
static auto rFormatterRun = registerCommand2<CmdFormatterRun>({"formatter", "run"});
|
||||||
|
|
||||||
struct CmdFormatterBuild : SourceExprCommand
|
struct CmdFormatterBuild : MixFormatter
|
||||||
{
|
{
|
||||||
Path outLink = "result";
|
Path outLink = "result";
|
||||||
|
|
||||||
|
@ -128,16 +132,6 @@ struct CmdFormatterBuild : SourceExprCommand
|
||||||
return catSecondary;
|
return catSecondary;
|
||||||
}
|
}
|
||||||
|
|
||||||
Strings getDefaultFlakeAttrPaths() override
|
|
||||||
{
|
|
||||||
return Strings{"formatter." + settings.thisSystem.get()};
|
|
||||||
}
|
|
||||||
|
|
||||||
Strings getDefaultFlakeAttrPathPrefixes() override
|
|
||||||
{
|
|
||||||
return Strings{};
|
|
||||||
}
|
|
||||||
|
|
||||||
void run(ref<Store> store) override
|
void run(ref<Store> store) override
|
||||||
{
|
{
|
||||||
auto evalState = getEvalState();
|
auto evalState = getEvalState();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue