aboutsummaryrefslogtreecommitdiff
path: root/src/nix
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2021-01-25 14:38:15 +0100
committerEelco Dolstra <edolstra@gmail.com>2021-01-25 14:38:15 +0100
commitb159d23800eec55412621a0b3e6c926a1dbb1755 (patch)
tree2d9e4b911548c7f1668bdd507a8757cd70658445 /src/nix
parent488a826842296c9c2933fb53cc884ed8518f9110 (diff)
Make '--help' do the same as 'help' (i.e. show a manpage)
Diffstat (limited to 'src/nix')
-rw-r--r--src/nix/command.cc5
-rw-r--r--src/nix/command.hh2
-rw-r--r--src/nix/main.cc61
-rw-r--r--src/nix/nar.cc5
-rw-r--r--src/nix/store.cc5
5 files changed, 17 insertions, 61 deletions
diff --git a/src/nix/command.cc b/src/nix/command.cc
index ba58c7d6b..20eeefe91 100644
--- a/src/nix/command.cc
+++ b/src/nix/command.cc
@@ -27,11 +27,6 @@ nix::Commands RegisterCommand::getCommandsFor(const std::vector<std::string> & p
return res;
}
-void NixMultiCommand::printHelp(const string & programName, std::ostream & out)
-{
- MultiCommand::printHelp(programName, out);
-}
-
nlohmann::json NixMultiCommand::toJSON()
{
// FIXME: use Command::toJSON() as well.
diff --git a/src/nix/command.hh b/src/nix/command.hh
index f325cd906..791dd0f1e 100644
--- a/src/nix/command.hh
+++ b/src/nix/command.hh
@@ -25,8 +25,6 @@ static constexpr Command::Category catNixInstallation = 102;
struct NixMultiCommand : virtual MultiCommand, virtual Command
{
- void printHelp(const string & programName, std::ostream & out) override;
-
nlohmann::json toJSON() override;
};
diff --git a/src/nix/main.cc b/src/nix/main.cc
index 80422bd24..77a13c913 100644
--- a/src/nix/main.cc
+++ b/src/nix/main.cc
@@ -54,6 +54,8 @@ static bool haveInternet()
std::string programPath;
char * * savedArgv;
+struct HelpRequested { };
+
struct NixArgs : virtual MultiCommand, virtual MixCommonArgs
{
bool printBuildLogs = false;
@@ -71,22 +73,7 @@ struct NixArgs : virtual MultiCommand, virtual MixCommonArgs
addFlag({
.longName = "help",
.description = "Show usage information.",
- .handler = {[&]() { if (!completions) showHelpAndExit(); }},
- });
-
- addFlag({
- .longName = "help-config",
- .description = "Show configuration settings.",
- .handler = {[&]() {
- std::cout << "The following configuration settings are available:\n\n";
- Table2 tbl;
- std::map<std::string, Config::SettingInfo> settings;
- globalConfig.getSettings(settings);
- for (const auto & s : settings)
- tbl.emplace_back(s.first, s.second.description);
- printTable(std::cout, tbl);
- throw Exit();
- }},
+ .handler = {[&]() { throw HelpRequested(); }},
});
addFlag({
@@ -154,33 +141,6 @@ struct NixArgs : virtual MultiCommand, virtual MixCommonArgs
return pos;
}
- void printFlags(std::ostream & out) override
- {
- Args::printFlags(out);
- std::cout <<
- "\n"
- "In addition, most configuration settings can be overriden using '--" ANSI_ITALIC "name value" ANSI_NORMAL "'.\n"
- "Boolean settings can be overriden using '--" ANSI_ITALIC "name" ANSI_NORMAL "' or '--no-" ANSI_ITALIC "name" ANSI_NORMAL "'. See 'nix\n"
- "--help-config' for a list of configuration settings.\n";
- }
-
- void printHelp(const string & programName, std::ostream & out) override
- {
- MultiCommand::printHelp(programName, out);
-
-#if 0
- out << "\nFor full documentation, run 'man " << programName << "' or 'man " << programName << "-" ANSI_ITALIC "COMMAND" ANSI_NORMAL "'.\n";
-#endif
-
- std::cout << "\nNote: this program is " ANSI_RED "EXPERIMENTAL" ANSI_NORMAL " and subject to change.\n";
- }
-
- void showHelpAndExit()
- {
- printHelp(programName, std::cout);
- throw Exit();
- }
-
std::string description() override
{
return "a tool for reproducible and declarative configuration management";
@@ -298,6 +258,18 @@ void mainWrapped(int argc, char * * argv)
try {
args.parseCmdline(argvToStrings(argc, argv));
+ } catch (HelpRequested &) {
+ std::vector<std::string> subcommand;
+ MultiCommand * command = &args;
+ while (command) {
+ if (command && command->command) {
+ subcommand.push_back(command->command->first);
+ command = dynamic_cast<MultiCommand *>(&*command->command->second);
+ } else
+ break;
+ }
+ showHelp(subcommand);
+ return;
} catch (UsageError &) {
if (!completions) throw;
}
@@ -306,7 +278,8 @@ void mainWrapped(int argc, char * * argv)
initPlugins();
- if (!args.command) args.showHelpAndExit();
+ if (!args.command)
+ throw UsageError("no subcommand specified");
if (args.command->first != "repl"
&& args.command->first != "doctor"
diff --git a/src/nix/nar.cc b/src/nix/nar.cc
index 0775d3c25..dbb043d9b 100644
--- a/src/nix/nar.cc
+++ b/src/nix/nar.cc
@@ -28,11 +28,6 @@ struct CmdNar : NixMultiCommand
command->second->prepare();
command->second->run();
}
-
- void printHelp(const string & programName, std::ostream & out) override
- {
- MultiCommand::printHelp(programName, out);
- }
};
static auto rCmdNar = registerCommand<CmdNar>("nar");
diff --git a/src/nix/store.cc b/src/nix/store.cc
index e91bcc503..44e53c7c7 100644
--- a/src/nix/store.cc
+++ b/src/nix/store.cc
@@ -21,11 +21,6 @@ struct CmdStore : virtual NixMultiCommand
command->second->prepare();
command->second->run();
}
-
- void printHelp(const string & programName, std::ostream & out) override
- {
- MultiCommand::printHelp(programName, out);
- }
};
static auto rCmdStore = registerCommand<CmdStore>("store");