aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/libcmd/command.cc10
-rw-r--r--src/libcmd/command.hh12
-rw-r--r--src/libcmd/installables.cc7
-rw-r--r--src/nix/diff-closures.cc2
-rw-r--r--src/nix/why-depends.cc2
5 files changed, 20 insertions, 13 deletions
diff --git a/src/libcmd/command.cc b/src/libcmd/command.cc
index 0740ea960..517cdf617 100644
--- a/src/libcmd/command.cc
+++ b/src/libcmd/command.cc
@@ -127,6 +127,16 @@ ref<EvalState> EvalCommand::getEvalState()
return ref<EvalState>(evalState);
}
+MixOperateOnOptions::MixOperateOnOptions()
+{
+ addFlag({
+ .longName = "derivation",
+ .description = "Operate on the [store derivation](../../glossary.md#gloss-store-derivation) rather than its outputs.",
+ .category = installablesCategory,
+ .handler = {&operateOn, OperateOn::Derivation},
+ });
+}
+
BuiltPathsCommand::BuiltPathsCommand(bool recursive)
: recursive(recursive)
{
diff --git a/src/libcmd/command.hh b/src/libcmd/command.hh
index 3b4b40981..d16bdbc4b 100644
--- a/src/libcmd/command.hh
+++ b/src/libcmd/command.hh
@@ -96,9 +96,6 @@ struct SourceExprCommand : virtual Args, MixFlakeOptions
std::optional<std::string> expr;
bool readOnlyMode = false;
- // FIXME: move this; not all commands (e.g. 'nix run') use it.
- OperateOn operateOn = OperateOn::Output;
-
SourceExprCommand(bool supportReadOnlyMode = false);
std::vector<std::shared_ptr<Installable>> parseInstallables(
@@ -153,8 +150,15 @@ private:
std::string _installable{"."};
};
+struct MixOperateOnOptions : virtual Args
+{
+ OperateOn operateOn = OperateOn::Output;
+
+ MixOperateOnOptions();
+};
+
/* A command that operates on zero or more store paths. */
-struct BuiltPathsCommand : public InstallablesCommand
+struct BuiltPathsCommand : InstallablesCommand, virtual MixOperateOnOptions
{
private:
diff --git a/src/libcmd/installables.cc b/src/libcmd/installables.cc
index 24f458f1a..ff8261b09 100644
--- a/src/libcmd/installables.cc
+++ b/src/libcmd/installables.cc
@@ -167,13 +167,6 @@ SourceExprCommand::SourceExprCommand(bool supportReadOnlyMode)
.handler = {&expr}
});
- addFlag({
- .longName = "derivation",
- .description = "Operate on the [store derivation](../../glossary.md#gloss-store-derivation) rather than its outputs.",
- .category = installablesCategory,
- .handler = {&operateOn, OperateOn::Derivation},
- });
-
if (supportReadOnlyMode) {
addFlag({
.longName = "read-only",
diff --git a/src/nix/diff-closures.cc b/src/nix/diff-closures.cc
index 0621d662c..3489cc132 100644
--- a/src/nix/diff-closures.cc
+++ b/src/nix/diff-closures.cc
@@ -106,7 +106,7 @@ void printClosureDiff(
using namespace nix;
-struct CmdDiffClosures : SourceExprCommand
+struct CmdDiffClosures : SourceExprCommand, MixOperateOnOptions
{
std::string _before, _after;
diff --git a/src/nix/why-depends.cc b/src/nix/why-depends.cc
index 76125e5e4..a3a9dc698 100644
--- a/src/nix/why-depends.cc
+++ b/src/nix/why-depends.cc
@@ -27,7 +27,7 @@ static std::string filterPrintable(const std::string & s)
return res;
}
-struct CmdWhyDepends : SourceExprCommand
+struct CmdWhyDepends : SourceExprCommand, MixOperateOnOptions
{
std::string _package, _dependency;
bool all = false;