diff options
Diffstat (limited to 'src/libcmd/command.hh')
-rw-r--r-- | src/libcmd/command.hh | 54 |
1 files changed, 29 insertions, 25 deletions
diff --git a/src/libcmd/command.hh b/src/libcmd/command.hh index 0d84c8395..874ca3249 100644 --- a/src/libcmd/command.hh +++ b/src/libcmd/command.hh @@ -29,6 +29,9 @@ struct NixMultiCommand : virtual MultiCommand, virtual Command nlohmann::json toJSON() override; }; +// For the overloaded run methods +#pragma GCC diagnostic ignored "-Woverloaded-virtual" + /* A command that requires a Nix store. */ struct StoreCommand : virtual Command { @@ -97,10 +100,10 @@ struct SourceExprCommand : virtual Args, MixFlakeOptions SourceExprCommand(); - std::vector<std::shared_ptr<Installable>> parseInstallables( + Installables parseInstallables( ref<Store> store, std::vector<std::string> ss); - std::shared_ptr<Installable> parseInstallable( + ref<Installable> parseInstallable( ref<Store> store, const std::string & installable); virtual Strings getDefaultFlakeAttrPaths(); @@ -115,36 +118,43 @@ struct MixReadOnlyOption : virtual Args MixReadOnlyOption(); }; -/* A command that operates on a list of "installables", which can be - store paths, attribute paths, Nix expressions, etc. */ -struct InstallablesCommand : virtual Args, SourceExprCommand +/* Like InstallablesCommand but the installables are not loaded */ +struct RawInstallablesCommand : virtual Args, SourceExprCommand { - std::vector<std::shared_ptr<Installable>> installables; + RawInstallablesCommand(); - InstallablesCommand(); + virtual void run(ref<Store> store, std::vector<std::string> && rawInstallables) = 0; - void prepare() override; - Installables load(); + void run(ref<Store> store) override; - virtual bool useDefaultInstallables() { return true; } + // FIXME make const after CmdRepl's override is fixed up + virtual void applyDefaultInstallables(std::vector<std::string> & rawInstallables); bool readFromStdIn = false; std::vector<std::string> getFlakesForCompletion() override; -protected: +private: + + std::vector<std::string> rawInstallables; +}; +/* A command that operates on a list of "installables", which can be + store paths, attribute paths, Nix expressions, etc. */ +struct InstallablesCommand : RawInstallablesCommand +{ + virtual void run(ref<Store> store, Installables && installables) = 0; - std::vector<std::string> _installables; + void run(ref<Store> store, std::vector<std::string> && rawInstallables) override; }; /* A command that operates on exactly one "installable" */ struct InstallableCommand : virtual Args, SourceExprCommand { - std::shared_ptr<Installable> installable; - InstallableCommand(); - void prepare() override; + virtual void run(ref<Store> store, ref<Installable> installable) = 0; + + void run(ref<Store> store) override; std::vector<std::string> getFlakesForCompletion() override { @@ -179,22 +189,18 @@ public: BuiltPathsCommand(bool recursive = false); - using StoreCommand::run; - virtual void run(ref<Store> store, BuiltPaths && paths) = 0; - void run(ref<Store> store) override; + void run(ref<Store> store, Installables && installables) override; - bool useDefaultInstallables() override { return !all; } + void applyDefaultInstallables(std::vector<std::string> & rawInstallables) override; }; struct StorePathsCommand : public BuiltPathsCommand { StorePathsCommand(bool recursive = false); - using BuiltPathsCommand::run; - - virtual void run(ref<Store> store, std::vector<StorePath> && storePaths) = 0; + virtual void run(ref<Store> store, StorePaths && storePaths) = 0; void run(ref<Store> store, BuiltPaths && paths) override; }; @@ -202,11 +208,9 @@ struct StorePathsCommand : public BuiltPathsCommand /* A command that operates on exactly one store path. */ struct StorePathCommand : public StorePathsCommand { - using StorePathsCommand::run; - virtual void run(ref<Store> store, const StorePath & storePath) = 0; - void run(ref<Store> store, std::vector<StorePath> && storePaths) override; + void run(ref<Store> store, StorePaths && storePaths) override; }; /* A helper class for registering commands globally. */ |