aboutsummaryrefslogtreecommitdiff
path: root/src/nix
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2020-12-02 12:26:09 +0100
committerEelco Dolstra <edolstra@gmail.com>2020-12-02 23:23:23 +0100
commit148608ba6ddf93168e86525627bed755a474d21f (patch)
treef5643ee5b0cbb80a9eb096c3fd7d034ff48f4cbb /src/nix
parent1b79b5b983a6c775766bd0d1c7881042188998b8 (diff)
Add 'nix help'
Diffstat (limited to 'src/nix')
-rw-r--r--src/nix/main.cc44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/nix/main.cc b/src/nix/main.cc
index 5056ceb78..a75f8ae65 100644
--- a/src/nix/main.cc
+++ b/src/nix/main.cc
@@ -149,6 +149,50 @@ struct NixArgs : virtual MultiCommand, virtual MixCommonArgs
}
};
+static void showHelp(std::vector<std::string> subcommand)
+{
+ showManPage(subcommand.empty() ? "nix" : fmt("nix3-%s", concatStringsSep("-", subcommand)));
+}
+
+struct CmdHelp : Command
+{
+ std::vector<std::string> subcommand;
+
+ CmdHelp()
+ {
+ expectArgs({
+ .label = "subcommand",
+ .handler = {&subcommand},
+ });
+ }
+
+ std::string description() override
+ {
+ return "show help about 'nix' or a particular subcommand";
+ }
+
+ Examples examples() override
+ {
+ return {
+ Example{
+ "To show help about 'nix' in general:",
+ "nix help"
+ },
+ Example{
+ "To show help about a particular subcommand:",
+ "nix help run"
+ },
+ };
+ }
+
+ void run() override
+ {
+ showHelp(subcommand);
+ }
+};
+
+static auto rCmdHelp = registerCommand<CmdHelp>("help");
+
void mainWrapped(int argc, char * * argv)
{
/* The chroot helper needs to be run before any threads have been