Skip to content
This repository has been archived by the owner on Aug 22, 2023. It is now read-only.

Commit

Permalink
fix: add instance
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx committed Feb 3, 2018
1 parent f1e655b commit e479049
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
12 changes: 8 additions & 4 deletions src/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,23 @@ export namespace Command {
examples?: string[]
}

export interface Full extends Base {
export interface Class extends Base {
plugin?: Config.IPlugin
flags?: Parser.flags.Input<any>
args?: Parser.args.Input
new<T>(argv: string[], config?: Config.Options): T
new(argv: string[], config?: Config.Options): Instance
run(argv: string[], config?: Config.Options): Promise<any>
}

export interface Instance {
_run(argv: string[]): Promise<any>
}

export interface Plugin extends Command {
load(): Full
load(): Class
}

export function toCached(c: Full): Command {
export function toCached(c: Class): Command {
return {
title: c.title,
id: c.id,
Expand Down
2 changes: 1 addition & 1 deletion src/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export interface Hooks {
pjson: Config.IPlugin
}
prerun: {
Command: Config.Command.Full
Command: Config.Command.Class
argv: string[]
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export interface Manifest {
const debug = require('debug')('@anycli/config')

export namespace Manifest {
export type FindCommandCB = (id: string) => Config.Command.Full
export type FindCommandCB = (id: string) => Config.Command.Class

export function build(version: string, dir: string, findCommand: FindCommandCB): Manifest {
debug(`loading IDs from ${dir}`)
Expand Down
2 changes: 1 addition & 1 deletion src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export class Plugin implements IPlugin {
if (opts.must) throw new Error(`command ${id} not found`)
}

_findCommand(id: string): Config.Command.Full {
_findCommand(id: string): Config.Command.Class {
const search = (cmd: any) => {
if (_.isFunction(cmd.run)) return cmd
return Object.values(cmd).find((cmd: any) => _.isFunction(cmd.run))
Expand Down

0 comments on commit e479049

Please sign in to comment.