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 tj#806
  • Loading branch information
prokopsimek committed Jan 30, 2020
1 parent d9627f5 commit 4edd028
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 12 additions & 0 deletions typings/commander-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ function increaseVerbosity(v: any, total: number) {
return total + 1;
}

function syncCall() {
return "Sync success!";
}

async function asyncCall() {
return new Promise((resolve) => {
resolve("Async success!")
})
}

program
.version('0.0.1')
.usage('[options] <file ...>')
Expand Down Expand Up @@ -112,6 +122,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 4edd028

Please sign in to comment.