Skip to content

Commit

Permalink
Corrected handling of main and sub commands.
Browse files Browse the repository at this point in the history
  • Loading branch information
mattstrom committed May 15, 2018
1 parent 2bc2152 commit 62824f5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "commander-ts",
"version": "0.1.3",
"version": "0.1.4",
"description": "TypeScript decorators that enhance commander",
"keywords": [
"command line",
Expand Down
15 changes: 13 additions & 2 deletions src/decorators/command.decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,21 @@ export function command(): MethodDecorator {
}, chain);
}

chain.action((...args) => {
chain.action(async (...args) => {
const context = args[args.length - 1];
const cmdArgs = args.slice(0, args.length - 1);
target[propertyKey].apply(context, cmdArgs);

try {
const result = target[propertyKey].apply(target, cmdArgs);

if (result instanceof Promise) {
await result;
}
} catch {
process.exit(1);
} finally {
process.exit(0);
}
});
} catch (e) {
console.error(e.message);
Expand Down

0 comments on commit 62824f5

Please sign in to comment.