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:
parent
95a9a4cece
commit
34e592ea6a
|
@ -28,12 +28,6 @@ nix::Commands RegisterCommand::getCommandsFor(const std::vector<std::string> & p
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
nlohmann::json NixMultiCommand::toJSON()
|
|
||||||
{
|
|
||||||
// FIXME: use Command::toJSON() as well.
|
|
||||||
return MultiCommand::toJSON();
|
|
||||||
}
|
|
||||||
|
|
||||||
StoreCommand::StoreCommand()
|
StoreCommand::StoreCommand()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)";
|
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
|
// For the overloaded run methods
|
||||||
#pragma GCC diagnostic ignored "-Woverloaded-virtual"
|
#pragma GCC diagnostic ignored "-Woverloaded-virtual"
|
||||||
|
|
||||||
|
|
|
@ -440,6 +440,8 @@ bool MultiCommand::processArgs(const Strings & args, bool finish)
|
||||||
|
|
||||||
nlohmann::json MultiCommand::toJSON()
|
nlohmann::json MultiCommand::toJSON()
|
||||||
{
|
{
|
||||||
|
// FIXME: use Command::toJSON() as well.
|
||||||
|
|
||||||
auto cmds = nlohmann::json::object();
|
auto cmds = nlohmann::json::object();
|
||||||
|
|
||||||
for (auto & [name, commandFun] : commands) {
|
for (auto & [name, commandFun] : commands) {
|
||||||
|
|
|
@ -343,7 +343,7 @@ typedef std::map<std::string, std::function<ref<Command>()>> Commands;
|
||||||
* An argument parser that supports multiple subcommands,
|
* An argument parser that supports multiple subcommands,
|
||||||
* i.e. ‘<command> <subcommand>’.
|
* i.e. ‘<command> <subcommand>’.
|
||||||
*/
|
*/
|
||||||
class MultiCommand : virtual public Args
|
class MultiCommand : public Command
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Commands commands;
|
Commands commands;
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
using namespace nix;
|
using namespace nix;
|
||||||
|
|
||||||
struct CmdConfig : virtual NixMultiCommand
|
struct CmdConfig : virtual MultiCommand
|
||||||
{
|
{
|
||||||
CmdConfig() : MultiCommand(RegisterCommand::getCommandsFor({"config"}))
|
CmdConfig() : MultiCommand(RegisterCommand::getCommandsFor({"config"}))
|
||||||
{ }
|
{ }
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
using namespace nix;
|
using namespace nix;
|
||||||
|
|
||||||
struct CmdDerivation : virtual NixMultiCommand
|
struct CmdDerivation : virtual MultiCommand
|
||||||
{
|
{
|
||||||
CmdDerivation() : MultiCommand(RegisterCommand::getCommandsFor({"derivation"}))
|
CmdDerivation() : MultiCommand(RegisterCommand::getCommandsFor({"derivation"}))
|
||||||
{ }
|
{ }
|
||||||
|
|
|
@ -1464,7 +1464,7 @@ struct CmdFlakePrefetch : FlakeCommand, MixJSON
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct CmdFlake : NixMultiCommand
|
struct CmdFlake : MultiCommand
|
||||||
{
|
{
|
||||||
CmdFlake()
|
CmdFlake()
|
||||||
: MultiCommand({
|
: MultiCommand({
|
||||||
|
|
|
@ -124,7 +124,7 @@ struct CmdToBase : Command
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct CmdHash : NixMultiCommand
|
struct CmdHash : MultiCommand
|
||||||
{
|
{
|
||||||
CmdHash()
|
CmdHash()
|
||||||
: MultiCommand({
|
: MultiCommand({
|
||||||
|
|
|
@ -214,6 +214,11 @@ struct NixArgs : virtual MultiCommand, virtual MixCommonArgs, virtual RootArgs
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void run() override
|
||||||
|
{
|
||||||
|
command->second->run();
|
||||||
|
}
|
||||||
|
|
||||||
// Plugins may add new subcommands.
|
// Plugins may add new subcommands.
|
||||||
void pluginsInited() override
|
void pluginsInited() override
|
||||||
{
|
{
|
||||||
|
@ -528,7 +533,7 @@ void mainWrapped(int argc, char * * argv)
|
||||||
if (args.command->second->forceImpureByDefault()) {
|
if (args.command->second->forceImpureByDefault()) {
|
||||||
evalSettings.pureEval.setDefault(false);
|
evalSettings.pureEval.setDefault(false);
|
||||||
}
|
}
|
||||||
args.command->second->run();
|
args.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
using namespace nix;
|
using namespace nix;
|
||||||
|
|
||||||
struct CmdNar : NixMultiCommand
|
struct CmdNar : MultiCommand
|
||||||
{
|
{
|
||||||
CmdNar() : MultiCommand(RegisterCommand::getCommandsFor({"nar"}))
|
CmdNar() : MultiCommand(RegisterCommand::getCommandsFor({"nar"}))
|
||||||
{ }
|
{ }
|
||||||
|
|
|
@ -601,7 +601,7 @@ struct CmdProfileWipeHistory : virtual StoreCommand, MixDefaultProfile, MixDryRu
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct CmdProfile : NixMultiCommand
|
struct CmdProfile : MultiCommand
|
||||||
{
|
{
|
||||||
CmdProfile()
|
CmdProfile()
|
||||||
: MultiCommand({
|
: MultiCommand({
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
using namespace nix;
|
using namespace nix;
|
||||||
|
|
||||||
struct CmdRealisation : virtual NixMultiCommand
|
struct CmdRealisation : virtual MultiCommand
|
||||||
{
|
{
|
||||||
CmdRealisation() : MultiCommand(RegisterCommand::getCommandsFor({"realisation"}))
|
CmdRealisation() : MultiCommand(RegisterCommand::getCommandsFor({"realisation"}))
|
||||||
{ }
|
{ }
|
||||||
|
|
|
@ -204,7 +204,7 @@ struct CmdRegistryPin : RegistryCommand, EvalCommand
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct CmdRegistry : virtual NixMultiCommand
|
struct CmdRegistry : virtual MultiCommand
|
||||||
{
|
{
|
||||||
CmdRegistry()
|
CmdRegistry()
|
||||||
: MultiCommand({
|
: MultiCommand({
|
||||||
|
|
|
@ -199,7 +199,7 @@ struct CmdKeyConvertSecretToPublic : Command
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct CmdKey : NixMultiCommand
|
struct CmdKey : MultiCommand
|
||||||
{
|
{
|
||||||
CmdKey()
|
CmdKey()
|
||||||
: MultiCommand({
|
: MultiCommand({
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
using namespace nix;
|
using namespace nix;
|
||||||
|
|
||||||
struct CmdStore : virtual NixMultiCommand
|
struct CmdStore : virtual MultiCommand
|
||||||
{
|
{
|
||||||
CmdStore() : MultiCommand(RegisterCommand::getCommandsFor({"store"}))
|
CmdStore() : MultiCommand(RegisterCommand::getCommandsFor({"store"}))
|
||||||
{ }
|
{ }
|
||||||
|
|
Loading…
Reference in a new issue