Skip to content

Commit

Permalink
support hidden:true on option spec to exclude it from help
Browse files Browse the repository at this point in the history
  • Loading branch information
trentm committed Mar 26, 2015
1 parent 7f0f6ab commit 22758ba
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 5 deletions.
7 changes: 4 additions & 3 deletions CHANGES.md
@@ -1,8 +1,9 @@
# node-dashdash changelog

## 1.7.4 (not yet released)
## 1.8.0 (not yet released)

(nothing yet)
- Support `hidden: true` in an option spec to have help output exclude this
option.


## 1.7.3
Expand Down Expand Up @@ -36,7 +37,7 @@

## 1.7.0

- [pull #7] Support for `<parser>.help({helpWrap: false, ...})` option be able
- [pull #7] Support for `<parser>.help({helpWrap: false, ...})` option to be able
to fully control the formatting for option help (by Patrick Mooney) `helpWrap:
false` can also be set on individual options in the option objects, e.g.:

Expand Down
3 changes: 3 additions & 0 deletions README.md
Expand Up @@ -348,6 +348,9 @@ Each option spec in the `options` array must/can have the following fields:
- `default`. Optional. A default value used for this option, if the
option isn't specified in argv.
- `hidden` (Boolean). Optional, default false. If true, help output will not
include this option.
# Option group headings
Expand Down
12 changes: 11 additions & 1 deletion lib/dashdash.js
Expand Up @@ -298,6 +298,7 @@ function Parser(config) {
format('config.options.%d.helpGroup', i));
assert.optionalBool(o.helpWrap,
format('config.options.%d.helpWrap', i));
assert.optionalBool(o.hidden, format('config.options.%d.hidden', i));

if (o.name) {
o.names = [o.name];
Expand Down Expand Up @@ -573,6 +574,9 @@ Parser.prototype.help = function help(config) {
var lines = [];
var maxWidth = 0;
this.options.forEach(function (o) {
if (o.hidden) {
return;
}
if (o.group !== undefined && o.group !== null) {
// We deal with groups in the next pass
lines.push(null);
Expand Down Expand Up @@ -615,7 +619,13 @@ Parser.prototype.help = function help(config) {
helpCol = maxWidth + indent.length + 2;
helpCol = Math.min(Math.max(helpCol, minHelpCol), maxHelpCol);
}
this.options.forEach(function (o, i) {
var i = -1;
this.options.forEach(function (o) {
if (o.hidden) {
return;
}
i++;

if (o.group !== undefined && o.group !== null) {
if (o.group === '') {
// Support a empty string "group" to have a blank line between
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,7 +1,7 @@
{
"name": "dashdash",
"description": "A light, featureful and explicit option parsing library.",
"version": "1.7.4",
"version": "1.8.0",
"author": "Trent Mick <trentm@gmail.com> (http://trentm.com)",
"keywords": ["option", "parser", "parsing", "cli", "command", "args"],
"repository": {
Expand Down
11 changes: 11 additions & 0 deletions test/basics.test.js
Expand Up @@ -995,6 +995,17 @@ var cases = [
]
/* END JSSTYLED */
},

// hidden
{
options: [
{names: ['help', 'h'], type: 'bool'},
{names: ['timeout', 't'], type: 'number', hidden: true},
{names: ['version'], type: 'bool'},
],
argv: 'node hidden-opts.js --help',
expectHelp: /-h, --help\n\s+--version/m,
},
];

cases.forEach(function (c, num) {
Expand Down

0 comments on commit 22758ba

Please sign in to comment.