Commit 3a967c59 authored by Doug Huff's avatar Doug Huff Committed by Facebook GitHub Bot

NestedCommandLineApp Add -h as an alias for --help globally and to all subcommands

Summary: Alias `-h` to `--help` because we live in a society.

Reviewed By: yfeldblum

Differential Revision: D27370742

fbshipit-source-id: eb346546fe4066eef62313176ff7e47c20e507be
parent 552024d3
......@@ -72,6 +72,7 @@ NestedCommandLineApp::NestedCommandLineApp(
displayHelp(vm, args);
});
builtinCommands_.insert(kHelpCommand);
addAlias(kShortHelpCommand.str(), kHelpCommand.str());
addCommand(
kVersionCommand.str(),
......@@ -84,7 +85,7 @@ NestedCommandLineApp::NestedCommandLineApp(
builtinCommands_.insert(kVersionCommand);
globalOptions_.add_options()(
kHelpCommand.str().c_str(),
(kHelpCommand.str() + "," + kShortHelpCommand.str()).c_str(),
"Display help (globally or for a given command)")(
kVersionCommand.str().c_str(), "Display version information");
}
......
......@@ -61,6 +61,7 @@ class NestedCommandLineApp {
Command;
static constexpr StringPiece const kHelpCommand = "help";
static constexpr StringPiece const kShortHelpCommand = "h";
static constexpr StringPiece const kVersionCommand = "version";
/**
* Initialize the app.
......
......@@ -75,6 +75,10 @@ TEST(ProgramOptionsTest, Errors) {
TEST(ProgramOptionsTest, Help) {
// Not actually checking help output, just verifying that help doesn't fail
callHelper({"--version"});
callHelper({"--h"});
callHelper({"--h", "foo"});
callHelper({"--h", "bar"});
callHelper({"--h", "--", "bar"});
callHelper({"--help"});
callHelper({"--help", "foo"});
callHelper({"--help", "bar"});
......@@ -84,6 +88,7 @@ TEST(ProgramOptionsTest, Help) {
callHelper({"help", "bar"});
// wrong command name
callHelper({"-h", "qux"}, 1);
callHelper({"--help", "qux"}, 1);
callHelper({"help", "qux"}, 1);
......@@ -93,6 +98,7 @@ TEST(ProgramOptionsTest, Help) {
TEST(ProgramOptionsTest, DevFull) {
folly::File full("/dev/full", O_RDWR);
callHelper({"-h"}, 1, full.fd());
callHelper({"--help"}, 1, full.fd());
}
......
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