aboutsummaryrefslogtreecommitdiff
path: root/src/libcmd
diff options
context:
space:
mode:
authoreldritch horrors <pennae@lix.systems>2024-03-04 04:38:33 +0100
committereldritch horrors <pennae@lix.systems>2024-03-04 04:38:33 +0100
commitd28a6618a886427aea26b2d356680eb569b7a036 (patch)
tree630a3b8cce9d8832bd53452568806fb63626286e /src/libcmd
parent7d8b34475aa94b607995df7f4b94c9042dd57058 (diff)
Merge pull request #9167 from obsidiansystems/pre-overhaul-completions
Improve tests and docs prior to refactoring completions (cherry picked from commit 5442d9b47298389918d1f38d20f768a80ffc2369) Change-Id: Ief99ac2cd9c92981a9a522d15b9c3daf99182c9d
Diffstat (limited to 'src/libcmd')
-rw-r--r--src/libcmd/command.hh78
1 files changed, 66 insertions, 12 deletions
diff --git a/src/libcmd/command.hh b/src/libcmd/command.hh
index 96236b987..5c4569001 100644
--- a/src/libcmd/command.hh
+++ b/src/libcmd/command.hh
@@ -34,21 +34,28 @@ struct NixMultiCommand : virtual MultiCommand, virtual Command
// For the overloaded run methods
#pragma GCC diagnostic ignored "-Woverloaded-virtual"
-/* A command that requires a Nix store. */
+/**
+ * A command that requires a \ref Store "Nix store".
+ */
struct StoreCommand : virtual Command
{
StoreCommand();
void run() override;
ref<Store> getStore();
virtual ref<Store> createStore();
+ /**
+ * Main entry point, with a `Store` provided
+ */
virtual void run(ref<Store>) = 0;
private:
std::shared_ptr<Store> _store;
};
-/* A command that copies something between `--from` and `--to`
- stores. */
+/**
+ * A command that copies something between `--from` and `--to` \ref
+ * Store stores.
+ */
struct CopyCommand : virtual StoreCommand
{
std::string srcUri, dstUri;
@@ -60,6 +67,9 @@ struct CopyCommand : virtual StoreCommand
ref<Store> getDstStore();
};
+/**
+ * A command that needs to evaluate Nix language expressions.
+ */
struct EvalCommand : virtual StoreCommand, MixEvalArgs
{
bool startReplOnEvalErrors = false;
@@ -79,6 +89,10 @@ private:
std::shared_ptr<EvalState> evalState;
};
+/**
+ * A mixin class for commands that process flakes, adding a few standard
+ * flake-related options/flags.
+ */
struct MixFlakeOptions : virtual Args, EvalCommand
{
flake::LockFlags lockFlags;
@@ -87,6 +101,14 @@ struct MixFlakeOptions : virtual Args, EvalCommand
MixFlakeOptions();
+ /**
+ * The completion for some of these flags depends on the flake(s) in
+ * question.
+ *
+ * This method should be implemented to gather all flakerefs the
+ * command is operating with (presumably specified via some other
+ * arguments) so that the completions for these flags can use them.
+ */
virtual std::vector<std::string> getFlakesForCompletion()
{ return {}; }
@@ -112,15 +134,29 @@ struct SourceExprCommand : virtual Args, MixFlakeOptions
virtual Strings getDefaultFlakeAttrPathPrefixes();
+ /**
+ * Complete an installable from the given prefix.
+ */
void completeInstallable(std::string_view prefix);
};
+/**
+ * A mixin class for commands that need a read-only flag.
+ *
+ * What exactly is "read-only" is unspecified, but it will usually be
+ * the \ref Store "Nix store".
+ */
struct MixReadOnlyOption : virtual Args
{
MixReadOnlyOption();
};
-/* Like InstallablesCommand but the installables are not loaded */
+/**
+ * Like InstallablesCommand but the installables are not loaded.
+ *
+ * This is needed by `CmdRepl` which wants to load (and reload) the
+ * installables itself.
+ */
struct RawInstallablesCommand : virtual Args, SourceExprCommand
{
RawInstallablesCommand();
@@ -129,7 +165,7 @@ struct RawInstallablesCommand : virtual Args, SourceExprCommand
void run(ref<Store> store) override;
- // FIXME make const after CmdRepl's override is fixed up
+ // FIXME make const after `CmdRepl`'s override is fixed up
virtual void applyDefaultInstallables(std::vector<std::string> & rawInstallables);
bool readFromStdIn = false;
@@ -140,8 +176,11 @@ 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. */
+
+/**
+ * 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;
@@ -149,7 +188,9 @@ struct InstallablesCommand : RawInstallablesCommand
void run(ref<Store> store, std::vector<std::string> && rawInstallables) override;
};
-/* A command that operates on exactly one "installable" */
+/**
+ * A command that operates on exactly one "installable".
+ */
struct InstallableCommand : virtual Args, SourceExprCommand
{
InstallableCommand();
@@ -175,7 +216,12 @@ struct MixOperateOnOptions : virtual Args
MixOperateOnOptions();
};
-/* A command that operates on zero or more store paths. */
+/**
+ * A command that operates on zero or more extant store paths.
+ *
+ * If the argument the user passes is a some sort of recipe for a path
+ * not yet built, it must be built first.
+ */
struct BuiltPathsCommand : InstallablesCommand, virtual MixOperateOnOptions
{
private:
@@ -207,7 +253,9 @@ struct StorePathsCommand : public BuiltPathsCommand
void run(ref<Store> store, BuiltPaths && paths) override;
};
-/* A command that operates on exactly one store path. */
+/**
+ * A command that operates on exactly one store path.
+ */
struct StorePathCommand : public StorePathsCommand
{
virtual void run(ref<Store> store, const StorePath & storePath) = 0;
@@ -215,7 +263,9 @@ struct StorePathCommand : public StorePathsCommand
void run(ref<Store> store, StorePaths && storePaths) override;
};
-/* A helper class for registering commands globally. */
+/**
+ * A helper class for registering \ref Command commands globally.
+ */
struct RegisterCommand
{
typedef std::map<std::vector<std::string>, std::function<ref<Command>()>> Commands;
@@ -271,7 +321,11 @@ struct MixEnvironment : virtual Args {
MixEnvironment();
- /* Modify global environ based on ignoreEnvironment, keep, and unset. It's expected that exec will be called before this class goes out of scope, otherwise environ will become invalid. */
+ /***
+ * Modify global environ based on `ignoreEnvironment`, `keep`, and
+ * `unset`. It's expected that exec will be called before this class
+ * goes out of scope, otherwise `environ` will become invalid.
+ */
void setEnviron();
};