diff --git a/src/nix/formatter.cc b/src/nix/formatter.cc index 0f915e7c9..31275eb35 100644 --- a/src/nix/formatter.cc +++ b/src/nix/formatter.cc @@ -27,7 +27,21 @@ struct CmdFormatter : NixMultiCommand static auto rCmdFormatter = registerCommand("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 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) override { auto evalState = getEvalState(); @@ -89,7 +93,7 @@ struct CmdFormatterRun : SourceExprCommand, MixJSON static auto rFormatterRun = registerCommand2({"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) override { auto evalState = getEvalState();