Skip to content

Commit bfba901

Browse files
committed
Make empty command check more robust
The commands name `help` and `version` are defined by the args library. Here we get a list of commands that doesn't include those. If there are other subcommands (and we haven't specified one), show a list of them.
1 parent c700204 commit bfba901

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

src/lib/cli/command.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,20 @@ args.argv = async function( argv, cb ): Promise<any> {
5050
// Check for updates every day
5151
updateNotifier( { pkg, isGlobal: true, updateCheckInterval: 1000 * 60 * 60 * 24 } ).notify();
5252

53-
// Show help if no args passed
5453
// `help` and `version` are always defined as subcommands
55-
const defaultSubcommandCount = 2;
56-
if ( this.details.commands.length > defaultSubcommandCount && ! this.sub.length ) {
54+
const customCommands = this.details.commands.filter( c => {
55+
switch ( c.usage ) {
56+
case 'help':
57+
case 'version':
58+
return false;
59+
60+
default:
61+
return true;
62+
}
63+
} );
64+
65+
// Show help if no args passed
66+
if ( !! customCommands.length && ! this.sub.length ) {
5767
await trackEvent( 'command_help_view' );
5868

5969
this.showHelp();

0 commit comments

Comments
 (0)