Skip to content

Commit

Permalink
feat(command): pass command to completion handler
Browse files Browse the repository at this point in the history
  • Loading branch information
c4spar committed Jun 14, 2020
1 parent 8dfe004 commit 1e8d51b
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/command/commands/completions/complete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class CompleteCommand extends DefaultCommand {
}

const completion: ICompleteSettings | undefined = cmd.getCompletion( action );
const result: string[] = await completion?.complete() ?? [];
const result: string[] = await completion?.complete( cmd ) ?? [];

if ( result?.length ) {
Deno.stdout.writeSync( encode( result.join( ' ' ) ) );
Expand Down
2 changes: 1 addition & 1 deletion packages/command/lib/base-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ export class BaseCommand<O = any, A extends Array<any> = any> {
this.cmd.types.set( name, { ...options, name, handler } );

if ( handler instanceof Type && typeof handler.complete !== 'undefined' ) {
this.complete( name, () => handler.complete?.() || [], options );
this.complete( name, ( cmd: BaseCommand ) => handler.complete?.( cmd ) || [], options );
}

return this;
Expand Down
2 changes: 1 addition & 1 deletion packages/command/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export interface ICompleteSettings extends ICompleteOptions {
}

/** Type parser method. */
export type ICompleteHandler = () => string[] | Promise<string[]>;
export type ICompleteHandler = ( cmd: BaseCommand ) => string[] | Promise<string[]>;

export interface IHelpCommand<O = any> extends BaseCommand<O> {
show( name?: string ): void;
Expand Down
3 changes: 2 additions & 1 deletion packages/command/types/type.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { IFlagArgument, IFlagOptions } from '../../flags/lib/types.ts';
import { BaseCommand } from '../lib/base-command.ts';

export abstract class Type<T> {

public abstract parse( option: IFlagOptions, arg: IFlagArgument, value: string ): T

public complete?(): string[];
public complete?( cmd: BaseCommand ): string[];
}

0 comments on commit 1e8d51b

Please sign in to comment.