Commit 3c0df746 authored by Brian Smith's avatar Brian Smith Committed by Facebook Github Bot

Add additional points to configure help output

Summary: Sometimes tools need to output a little more help context before or after help.

Reviewed By: yfeldblum

Differential Revision: D4719112

fbshipit-source-id: e6f59312d722e0669053644d862c81758855b538
parent 69bd8deb
...@@ -48,11 +48,15 @@ ProgramExit::ProgramExit(int status, const std::string& msg) ...@@ -48,11 +48,15 @@ ProgramExit::ProgramExit(int status, const std::string& msg)
NestedCommandLineApp::NestedCommandLineApp( NestedCommandLineApp::NestedCommandLineApp(
std::string programName, std::string programName,
std::string version, std::string version,
std::string programHeading,
std::string programHelpFooter,
InitFunction initFunction) InitFunction initFunction)
: programName_(std::move(programName)), : programName_(std::move(programName)),
version_(std::move(version)), programHeading_(std::move(programHeading)),
initFunction_(std::move(initFunction)), programHelpFooter_(std::move(programHelpFooter)),
globalOptions_("Global options") { version_(std::move(version)),
initFunction_(std::move(initFunction)),
globalOptions_("Global options") {
addCommand("help", "[command]", addCommand("help", "[command]",
"Display help (globally or for a given command)", "Display help (globally or for a given command)",
"Displays help (globally or for a given command).", "Displays help (globally or for a given command).",
...@@ -101,8 +105,10 @@ void NestedCommandLineApp::displayHelp( ...@@ -101,8 +105,10 @@ void NestedCommandLineApp::displayHelp(
if (args.empty()) { if (args.empty()) {
// General help // General help
printf( printf(
"Usage: %s [global_options...] <command> [command_options...] " "%s\nUsage: %s [global_options...] <command> [command_options...] "
"[command_args...]\n\n", programName_.c_str()); "[command_args...]\n\n",
programHeading_.c_str(),
programName_.c_str());
std::cout << globalOptions_; std::cout << globalOptions_;
printf("\nAvailable commands:\n"); printf("\nAvailable commands:\n");
...@@ -126,6 +132,7 @@ void NestedCommandLineApp::displayHelp( ...@@ -126,6 +132,7 @@ void NestedCommandLineApp::displayHelp(
int(maxLen), p.first.c_str(), resolveAlias(p.second).c_str()); int(maxLen), p.first.c_str(), resolveAlias(p.second).c_str());
} }
} }
std::cout << "\n" << programHelpFooter_ << "\n";
} else { } else {
// Help for a given command // Help for a given command
auto& p = findCommand(args.front()); auto& p = findCommand(args.front());
......
...@@ -67,6 +67,8 @@ class NestedCommandLineApp { ...@@ -67,6 +67,8 @@ class NestedCommandLineApp {
explicit NestedCommandLineApp( explicit NestedCommandLineApp(
std::string programName = std::string(), std::string programName = std::string(),
std::string version = std::string(), std::string version = std::string(),
std::string programHeading = std::string(),
std::string programHelpFooter = std::string(),
InitFunction initFunction = InitFunction()); InitFunction initFunction = InitFunction());
/** /**
...@@ -142,6 +144,8 @@ class NestedCommandLineApp { ...@@ -142,6 +144,8 @@ class NestedCommandLineApp {
const std::vector<std::string>& args); const std::vector<std::string>& args);
std::string programName_; std::string programName_;
std::string programHeading_;
std::string programHelpFooter_;
std::string version_; std::string version_;
InitFunction initFunction_; InitFunction initFunction_;
boost::program_options::options_description globalOptions_; boost::program_options::options_description globalOptions_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment