libcmd, nix: drop NixMultiCommand

there are no uses of plain MultiCommand as a base class *except* in
NixArgs, which is the only one that does not implement run(). there
is not much of a reason not to implement a run member there though,
so let's just do that and get rid of this weird intermediate class.

Change-Id: Ie84e3acd071b43bc186a2bac87646cbfb3aff845
This commit is contained in:
eldritch horrors 2024-11-17 14:43:57 +01:00
parent 95a9a4cece
commit 34e592ea6a
15 changed files with 19 additions and 23 deletions

View file

@ -28,12 +28,6 @@ nix::Commands RegisterCommand::getCommandsFor(const std::vector<std::string> & p
return res;
}
nlohmann::json NixMultiCommand::toJSON()
{
// FIXME: use Command::toJSON() as well.
return MultiCommand::toJSON();
}
StoreCommand::StoreCommand()
{
}

View file

@ -26,11 +26,6 @@ static constexpr Command::Category catNixInstallation = 102;
static constexpr auto installablesCategory = "Options that change the interpretation of [installables](@docroot@/command-ref/new-cli/nix.md#installables)";
struct NixMultiCommand : virtual MultiCommand, virtual Command
{
nlohmann::json toJSON() override;
};
// For the overloaded run methods
#pragma GCC diagnostic ignored "-Woverloaded-virtual"

View file

@ -440,6 +440,8 @@ bool MultiCommand::processArgs(const Strings & args, bool finish)
nlohmann::json MultiCommand::toJSON()
{
// FIXME: use Command::toJSON() as well.
auto cmds = nlohmann::json::object();
for (auto & [name, commandFun] : commands) {

View file

@ -343,7 +343,7 @@ typedef std::map<std::string, std::function<ref<Command>()>> Commands;
* An argument parser that supports multiple subcommands,
* i.e. <command> <subcommand>.
*/
class MultiCommand : virtual public Args
class MultiCommand : public Command
{
public:
Commands commands;

View file

@ -7,7 +7,7 @@
using namespace nix;
struct CmdConfig : virtual NixMultiCommand
struct CmdConfig : virtual MultiCommand
{
CmdConfig() : MultiCommand(RegisterCommand::getCommandsFor({"config"}))
{ }

View file

@ -2,7 +2,7 @@
using namespace nix;
struct CmdDerivation : virtual NixMultiCommand
struct CmdDerivation : virtual MultiCommand
{
CmdDerivation() : MultiCommand(RegisterCommand::getCommandsFor({"derivation"}))
{ }

View file

@ -1464,7 +1464,7 @@ struct CmdFlakePrefetch : FlakeCommand, MixJSON
}
};
struct CmdFlake : NixMultiCommand
struct CmdFlake : MultiCommand
{
CmdFlake()
: MultiCommand({

View file

@ -124,7 +124,7 @@ struct CmdToBase : Command
}
};
struct CmdHash : NixMultiCommand
struct CmdHash : MultiCommand
{
CmdHash()
: MultiCommand({

View file

@ -214,6 +214,11 @@ struct NixArgs : virtual MultiCommand, virtual MixCommonArgs, virtual RootArgs
;
}
void run() override
{
command->second->run();
}
// Plugins may add new subcommands.
void pluginsInited() override
{
@ -528,7 +533,7 @@ void mainWrapped(int argc, char * * argv)
if (args.command->second->forceImpureByDefault()) {
evalSettings.pureEval.setDefault(false);
}
args.command->second->run();
args.run();
}
}

View file

@ -2,7 +2,7 @@
using namespace nix;
struct CmdNar : NixMultiCommand
struct CmdNar : MultiCommand
{
CmdNar() : MultiCommand(RegisterCommand::getCommandsFor({"nar"}))
{ }

View file

@ -601,7 +601,7 @@ struct CmdProfileWipeHistory : virtual StoreCommand, MixDefaultProfile, MixDryRu
}
};
struct CmdProfile : NixMultiCommand
struct CmdProfile : MultiCommand
{
CmdProfile()
: MultiCommand({

View file

@ -5,7 +5,7 @@
using namespace nix;
struct CmdRealisation : virtual NixMultiCommand
struct CmdRealisation : virtual MultiCommand
{
CmdRealisation() : MultiCommand(RegisterCommand::getCommandsFor({"realisation"}))
{ }

View file

@ -204,7 +204,7 @@ struct CmdRegistryPin : RegistryCommand, EvalCommand
}
};
struct CmdRegistry : virtual NixMultiCommand
struct CmdRegistry : virtual MultiCommand
{
CmdRegistry()
: MultiCommand({

View file

@ -199,7 +199,7 @@ struct CmdKeyConvertSecretToPublic : Command
}
};
struct CmdKey : NixMultiCommand
struct CmdKey : MultiCommand
{
CmdKey()
: MultiCommand({

View file

@ -2,7 +2,7 @@
using namespace nix;
struct CmdStore : virtual NixMultiCommand
struct CmdStore : virtual MultiCommand
{
CmdStore() : MultiCommand(RegisterCommand::getCommandsFor({"store"}))
{ }