Skip to content

Commit

Permalink
fix(ts): action can be an async function
Browse files Browse the repository at this point in the history
Since we can use `parseAsync` for async functions so the action can be asynchronous.

related to #806
  • Loading branch information
prokopsimek committed Jan 30, 2020
1 parent d9627f5 commit 72062a5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 10 additions & 0 deletions typings/commander-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ function increaseVerbosity(v: any, total: number) {
return total + 1;
}

function syncCall() {
console.log("Sync success!");
}

async function asyncCall() {
return;
}

program
.version('0.0.1')
.usage('[options] <file ...>')
Expand Down Expand Up @@ -112,6 +120,8 @@ program
program
.command("name1", "description")
.command("name2", "description", { isDefault:true })
.command("name3", "description").action(syncCall)
.command("name4", "description").action(asyncCall)

program
.exitOverride();
Expand Down
2 changes: 1 addition & 1 deletion typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ declare namespace commander {
*
* @returns Command for chaining
*/
action(fn: (...args: any[]) => void): Command;
action(fn: (...args: any[]) => void | Promise<void>): Command;

/**
* Define option with `flags`, `description` and optional
Expand Down

0 comments on commit 72062a5

Please sign in to comment.