Skip to content

Commit

Permalink
fix(command): help command fails with registered environment variables
Browse files Browse the repository at this point in the history
  • Loading branch information
c4spar committed May 24, 2020
1 parent 6835315 commit b176bd4
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 21 deletions.
42 changes: 23 additions & 19 deletions packages/command/commands/help.ts
Expand Up @@ -155,7 +155,7 @@ export class HelpCommand extends BaseCommand implements IHelpCommand {
return [
...cmd.getEnvVars().map( ( envVar: IEnvVariable ) => [
envVar.names.map( name => blue( name ) ).join( ', ' ),
this.highlight( envVar.type ),
this.highlightDetails( envVar.details ),
`${ red( bold( '-' ) ) } ${ envVar.description }`
] )
];
Expand Down Expand Up @@ -208,33 +208,37 @@ export class HelpCommand extends BaseCommand implements IHelpCommand {
return type;
}

return this.parseArgsDefinition( type ).map( ( arg: IArgumentDetails ) => {
return this.parseArgsDefinition( type ).map( ( arg: IArgumentDetails ) => this.highlightDetails( arg ) ).join( ' ' );
}

let str = '';
/**
* Colorize argument type's.
*/
protected highlightDetails( arg: IArgumentDetails ): string {

str += yellow( arg.optionalValue ? '[' : '<' );
let str = '';

let name = '';
name += arg.name;
if ( arg.variadic ) {
name += '...';
}
name = magenta( name );
str += yellow( arg.optionalValue ? '[' : '<' );

str += name;
let name = '';
name += arg.name;
if ( arg.variadic ) {
name += '...';
}
name = magenta( name );

str += yellow( ':' );
str += red( arg.type );
str += name;

if ( arg.list ) {
str += green( '[]' );
}
str += yellow( ':' );
str += red( arg.type );

str += yellow( arg.optionalValue ? ']' : '>' );
if ( arg.list ) {
str += green( '[]' );
}

return str;
str += yellow( arg.optionalValue ? ']' : '>' );

} ).join( ' ' );
return str;
}
}

Expand Down
16 changes: 14 additions & 2 deletions packages/command/test/command/help-command_test.ts
Expand Up @@ -2,10 +2,11 @@ import { stripeColors } from '../../../table/lib/utils.ts';
import { Command } from '../../lib/command.ts';
import { assertEquals } from '../lib/assert.ts';

Deno.test( 'hidden command help', async () => {
Deno.test( 'command: help command', async () => {

const cmd: Command = new Command()
.throwErrors()

.version( '1.0.0' )
.description( 'Test description ...' )
.option( '-t, --test [val:string]', 'test description' )
Expand All @@ -20,11 +21,17 @@ Deno.test( 'hidden command help', async () => {
depends: [ 'test' ],
conflicts: [ 'depends' ]
} )
.env( 'SOME_ENV_VAR=<value:number>', 'Description ...' )
.env( 'SOME_ENV_VAR_2 <value>', 'Description 2 ...' )

.command( 'sub-command <input:string> <output:string>' )
.description( 'sub command description.' )

.command( 'hidden-command <input:string> <output:string>' )
.description( 'Nobody knows about me!' )
.hidden();
.hidden()

.reset();

const output: string = cmd.getHelpCommand().getHelp();

Expand Down Expand Up @@ -53,5 +60,10 @@ Deno.test( 'hidden command help', async () => {
completions - Generate shell completions for zsh and bash.
sub-command <input:string> <output:string> - sub command description.
Environment variables:
SOME_ENV_VAR <value:number> - Description ...
SOME_ENV_VAR_2 <value:string> - Description 2 ...
` );
} );

0 comments on commit b176bd4

Please sign in to comment.