-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3065cc7
commit c18948d
Showing
4 changed files
with
71 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import * as inquirer from 'inquirer' | ||
|
||
interface BaseOptions<T> { | ||
message: string | ||
default?: T | ||
} | ||
|
||
interface InputOptions extends BaseOptions<string> {} | ||
|
||
export async function input(question: string | InputOptions): Promise<string> { | ||
if (typeof question === 'string') { | ||
question = { message: question } | ||
} | ||
const { answer } = await inquirer.prompt<{ answer: string }>({ ...question, name: 'answer' }) | ||
return answer | ||
} | ||
|
||
export async function password(question: string | InputOptions): Promise<string> { | ||
if (typeof question === 'string') { | ||
question = { message: question } | ||
} | ||
const { answer } = await inquirer.prompt<{ answer: string }>({ ...question, name: 'answer', type: 'password' }) | ||
return answer | ||
} | ||
|
||
interface ChoicesOptions<T extends string> extends BaseOptions<T> { | ||
choices: ReadonlyArray<T> | ||
} | ||
|
||
export async function choices<T extends string>(question: ChoicesOptions<T>): Promise<T> { | ||
const { answer } = await inquirer.prompt<{ answer: T }>({ ...question, name: 'answer', type: 'list' }) | ||
return answer | ||
} | ||
|
||
interface ConfirmOptions extends BaseOptions<boolean> {} | ||
|
||
export async function confirm(question: string | ConfirmOptions): Promise<boolean> { | ||
if (typeof question === 'string') { | ||
question = { message: question } | ||
} | ||
const { answer } = await inquirer.prompt<{ answer: boolean }>({ ...question, name: 'answer', type: 'confirm' }) | ||
return answer | ||
} |