Skip to content

Commit e84dcf8

Browse files
committed
add hideEmpty option. Fixes #8
1 parent 311acc6 commit e84dcf8

File tree

4 files changed

+37
-63
lines changed

4 files changed

+37
-63
lines changed

examples/advanced/gulpfile.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var gulp = require('../../index.js')(require('gulp'), { aliases: ['h', '?'] });
1+
var gulp = require('../../index.js')(require('gulp'), {aliases: ['h', '?']});
22

33
// --------------------------------------------------------------------------------------
44
// tasks

index.js

+14-6
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ var objectAssign = require('object-assign'),
77
aliases: [],
88
description: 'Display this help text.',
99
afterPrintCallback: noop,
10-
hideDepsMessage: false
10+
hideDepsMessage: false,
11+
hideEmpty: false
1112
};
1213

1314
module.exports = function (gulp, options) {
@@ -96,7 +97,10 @@ module.exports = function (gulp, options) {
9697
gulp.task('help', options.description, function () {
9798
var marginData = calculateMargin(gulp.tasks);
9899
var margin = marginData.margin;
99-
var hideDepsMessage = options.hideDepsMessage;
100+
var hideDepsMessageOpt = options.hideDepsMessage;
101+
var hideEmptyOpt = options.hideEmpty;
102+
var showAllTasks = process.argv.indexOf('--all') !== -1;
103+
var afterPrintCallback = options.afterPrintCallback;
100104

101105
// set options buffer if the tasks array has options
102106
var optionsBuffer = marginData.hasOptions ? ' --' : '';
@@ -107,8 +111,12 @@ module.exports = function (gulp, options) {
107111
console.log('');
108112
console.log(chalk.underline('Available tasks'));
109113
Object.keys(gulp.tasks).sort().forEach(function (name) {
110-
if (gulp.tasks[name].help || process.argv.indexOf('--all') !== -1) {
114+
if (gulp.tasks[name].help || showAllTasks) {
111115
var help = gulp.tasks[name].help || {message: '', options: {}};
116+
117+
if (!showAllTasks && help.message === '' && hideEmptyOpt) {
118+
return; //skip task
119+
}
112120
var args = [' ', chalk.cyan(name)];
113121

114122
args.push(new Array(margin - name.length + 1 + optionsBuffer.length).join(' '));
@@ -121,7 +129,7 @@ module.exports = function (gulp, options) {
121129
args.push(help.aliases);
122130
}
123131

124-
if (help.depsMessage && !hideDepsMessage) {
132+
if (help.depsMessage && !hideDepsMessageOpt) {
125133
args.push(chalk.cyan(help.depsMessage));
126134
}
127135

@@ -138,8 +146,8 @@ module.exports = function (gulp, options) {
138146
}
139147
});
140148
console.log('');
141-
if (options.afterPrintCallback) {
142-
options.afterPrintCallback(gulp.tasks);
149+
if (afterPrintCallback) {
150+
afterPrintCallback(gulp.tasks);
143151
}
144152
}, options);
145153

readme.md

+22-56
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,16 @@ Type: `string`
4343
Type: `string | boolean`
4444

4545
Custom help message as a string.
46-
If you want to hide the task from the help menu, supply `false`.
46+
47+
If you want to hide the task from the help menu, supply `false`
48+
49+
```js
50+
gulp.task('task-hidden-from-help', false, function () {
51+
// ...
52+
});
53+
```
54+
55+
However, if the `--all` flag is provided, even these tasks will be shown. (i.e. `gulp help --all`)
4756

4857
#### [deps](https://github.com/gulpjs/gulp/blob/master/docs/API.md#deps)
4958

@@ -57,23 +66,7 @@ Type: `function`
5766

5867
Type: `Array`
5968

60-
List of aliases for this task.
61-
62-
## Hide Tasks
63-
64-
You can optionally hide a target from showing up in the help menu by passing `false` as the help argument, e.g.
65-
66-
```js
67-
gulp.task('task-hidden-from-help', false, function () {
68-
// ...
69-
});
70-
```
71-
72-
However, if the `--all` flag is provided, even these tasks will be shown. (i.e. `gulp help --all`)
73-
74-
## Aliases
75-
76-
You can optionally add aliases to your targets by supplying an object with an aliases array, e.g.
69+
List of aliases for this task
7770

7871
```js
7972
gulp.task('version', 'prints the version.', [], function() {
@@ -87,9 +80,11 @@ which results in
8780

8881
![](screenshot-aliases.png)
8982

90-
## Options
83+
#### taskOptions.options
84+
85+
Type: `Object`
9186

92-
You can optionally pass options to your targets by supplying an object with an options object, e.g.
87+
Object documenting options which can be passed to your task
9388

9489
```js
9590
gulp.task('version', 'prints the version.', [], function () {
@@ -106,44 +101,15 @@ which results in
106101

107102
![](screenshot-options.png)
108103

109-
## Override default help message
110-
111-
```js
112-
require('gulp-help')(require('gulp'), { description: 'you are looking at it.', aliases: ['h', '?'] });
113-
```
114-
115-
Then, calling
116-
117-
```shell
118-
$ gulp #or
119-
$ gulp help #or
120-
$ gulp h #or
121-
$ gulp ?
122-
```
123-
124-
will now result in
125-
126-
![](screenshot-override-default.png)
104+
## require('gulp-help')(require('gulp'), options);
127105

128-
## Post-help callback
106+
These are all the options available to be passed to the `gulp-help` instance, NOT individual tasks.
129107

130-
You can define a function to run after the default help task runs.
131-
132-
```js
133-
require('gulp-help')(gulp, {
134-
afterPrintCallback: function(tasks) {
135-
console.log(tasks);
136-
}
137-
});
138-
```
139-
140-
## Hide task dependencies
141-
142-
By default, the dependencies of a task will be listed behind its help message. To hide them:
143-
144-
```js
145-
require('gulp-help')(require('gulp'), {hideDepsMessage:true});
146-
```
108+
- `description` - modifies the default help message
109+
- `aliases` - adds aliases to the default help task
110+
- `hideEmpty` - hide all tasks with no help message defined. Useful when including 3rd party tasks
111+
- `hideDepsMessage` - hide all task dependencies
112+
- `afterPrintCallback` - a function to run after the default help task runs
147113

148114
## License
149115

screenshot-override-default.png

-66.5 KB
Binary file not shown.

0 commit comments

Comments
 (0)