Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 32 additions & 58 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"apollo-cache-inmemory": "~1.1.7",
"apollo-client": "~2.2.3",
"apollo-link-http": "~1.3.3",
"args": "~3.0.8",
"args": "~5.0.0",
"chalk": "~2.4.1",
"cli-table": "github:automattic/cli-table#b9ebd75",
"configstore": "^3.1.2",
Expand Down
14 changes: 13 additions & 1 deletion src/lib/cli/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,20 @@ args.argv = async function( argv, cb ): Promise<any> {
// Check for updates every day
updateNotifier( { pkg, isGlobal: true, updateCheckInterval: 1000 * 60 * 60 * 24 } ).notify();

// `help` and `version` are always defined as subcommands
const customCommands = this.details.commands.filter( c => {
switch ( c.usage ) {
case 'help':
case 'version':
return false;

default:
return true;
}
} );

// Show help if no args passed
if ( this.details.commands.length > 1 && ! this.sub.length ) {
if ( !! customCommands.length && ! this.sub.length ) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are there two different bang policies here, both on a .length params?

Copy link
Copy Markdown
Contributor Author

@joshbetz joshbetz Jul 5, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a common Javascript way to cast something to a Boolean. The first casts the value to a Boolean but inverts it so the second one is needed to invert it back.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know, I just wanted to know why !! customCommands.length has 2 bangs while ! this.sub.length has only one, thought they were similar.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're checking to see if we have custom commands defined (!! customCommands.length; looking for true) and not passing any args (! this.sub.length; looking for false).

I think for clarity, this would be better written as:

if ( customCommands.length > 1
    && this.sub.length === 0 ) {

or take it a step further:

const haveCustomCommands = customCommands.length > 1;
const runningSubcommand = this.sub.length === 0;

if ( haveCustomCommands && ! runningSubcommand ) {

await trackEvent( 'command_help_view' );

this.showHelp();
Expand Down