Skip to content

Commit

Permalink
fix(command): default option incompatible with standalone option
Browse files Browse the repository at this point in the history
  • Loading branch information
c4spar committed May 21, 2020
1 parent 2f25d8b commit e9e6aa5
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions packages/command/lib/base-command.ts
Expand Up @@ -688,13 +688,14 @@ export class BaseCommand<O = any, A extends Array<any> = any> {
if ( !args.length ) {

const required = this.getArguments()
.filter( expectedArg => !expectedArg.optionalValue )
.map( expectedArg => expectedArg.name );
.filter( expectedArg => !expectedArg.optionalValue )
.map( expectedArg => expectedArg.name );

if ( required.length ) {
const flagNames: string[] = Object.keys( flags );
const isStandaloneOption: boolean | undefined = flagNames.length === 1 && this.getOption( flagNames[ 0 ] )?.standalone;
if ( required.length && !isStandaloneOption ) {
const hasStandaloneOption: boolean = !!flagNames.find( name => this.getOption( name )?.standalone );

if ( !hasStandaloneOption ) {
throw this.error( new Error( 'Missing argument(s): ' + required.join( ', ' ) ) );
}
}
Expand Down Expand Up @@ -883,9 +884,9 @@ export class BaseCommand<O = any, A extends Array<any> = any> {
public getShortDescription(): string {

return this.getDescription()
.trim()
.split( '\n' )
.shift() as string;
.trim()
.split( '\n' )
.shift() as string;
}

/**
Expand Down

0 comments on commit e9e6aa5

Please sign in to comment.