Comparing version 0.2.2 to 0.2.3
@@ -26,5 +26,7 @@ import { Container } from 'inversify'; | ||
yargs: Argv$1; | ||
private isInit; | ||
constructor({ container, yargs }?: CLIOptions); | ||
register(...commands: CommandStatic[]): this; | ||
run(processArgs: string[]): Promise<number>; | ||
private init; | ||
} | ||
@@ -31,0 +33,0 @@ |
@@ -53,3 +53,3 @@ "use strict"; | ||
store = {}; | ||
add(path, name, node) { | ||
addNode(path, name, node) { | ||
let target = this.store; | ||
@@ -71,2 +71,11 @@ for (const name2 of path) { | ||
} | ||
add(command) { | ||
const path = command.path ?? []; | ||
const [name] = command.command.split(" ", 2); | ||
this.addNode(path, name, { | ||
command, | ||
children: {} | ||
}); | ||
return this; | ||
} | ||
build(yargs, handle, store = this.store) { | ||
@@ -84,8 +93,3 @@ for (const [name, { command, children }] of Object.entries(store)) { | ||
for (const command of commands) { | ||
const path = command.path ?? []; | ||
const [name] = command.command.split(" ", 2); | ||
instance.add(path, name, { | ||
command, | ||
children: {} | ||
}); | ||
instance.add(command); | ||
} | ||
@@ -130,2 +134,3 @@ return instance; | ||
yargs; | ||
isInit = false; | ||
constructor({ container = createDefaultContainer(), yargs = (0, import_yargs.default)().help() } = {}) { | ||
@@ -143,13 +148,3 @@ this.container = container; | ||
const stderr = await this.container.getAsync(Stderr); | ||
const commands = await this.container.getAllAsync(Command); | ||
ArgvBuilder.from(commands).build(this.yargs, async (Command2, args) => { | ||
const container = this.container.createChild(); | ||
container.bind(_CLI).toConstantValue(this); | ||
container.bind(Argv).toConstantValue(this.yargs); | ||
container.bind(Args).toConstantValue(args); | ||
container.bind(Command2).toSelf(); | ||
const command = await container.getAsync(Command2); | ||
const commandResult = await command.execute(); | ||
args["$?"] = commandResult; | ||
}); | ||
await this.init(); | ||
return new Promise((resolve) => { | ||
@@ -170,2 +165,19 @@ this.yargs.parse(processArgs, {}, (error, argv, output) => { | ||
} | ||
async init() { | ||
if (this.isInit) { | ||
return; | ||
} | ||
const commands = await this.container.getAllAsync(Command); | ||
ArgvBuilder.from(commands).build(this.yargs, async (Command2, args) => { | ||
const container = this.container.createChild(); | ||
container.bind(_CLI).toConstantValue(this); | ||
container.bind(Argv).toConstantValue(this.yargs); | ||
container.bind(Args).toConstantValue(args); | ||
container.bind(Command2).toSelf(); | ||
const command = await container.getAsync(Command2); | ||
const commandResult = await command.execute(); | ||
args["$?"] = commandResult; | ||
}); | ||
this.isInit = true; | ||
} | ||
}; | ||
@@ -172,0 +184,0 @@ |
{ | ||
"name": "sgray", | ||
"version": "0.2.2", | ||
"version": "0.2.3", | ||
"author": "cumul <gg6123@naver.com>", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
34268
357