From bb4c3637093a8c89c2d24ad483b4209900a3752a Mon Sep 17 00:00:00 2001 From: Jeff Dickey <216188+jdxcode@users.noreply.github.com> Date: Sun, 6 May 2018 15:18:20 -0700 Subject: [PATCH] feat: default for prompt --- examples/prompt.ts | 5 ++++- test/prompt.test.ts | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/examples/prompt.ts b/examples/prompt.ts index ccd95d0e..30faba20 100644 --- a/examples/prompt.ts +++ b/examples/prompt.ts @@ -1,6 +1,6 @@ import {cli} from '../src' -const wait = (ms = 400) => new Promise(resolve => setTimeout(resolve, ms)) +const wait = (ms = 100) => new Promise(resolve => setTimeout(resolve, ms)) async function run() { cli.action.start('doing a thing') @@ -17,6 +17,9 @@ async function run() { cli.log(`you entered: ${input}`) input = await cli.prompt('your name (default)', {default: 'somedefault'}) await wait() + cli.log(`you entered: ${input}`) + input = await cli.prompt('your name (not required)', {required: false}) + await wait() cli.action.stop() cli.log(`you entered: ${input}`) } diff --git a/test/prompt.test.ts b/test/prompt.test.ts index 3b1e5ce3..d6b439b1 100644 --- a/test/prompt.test.ts +++ b/test/prompt.test.ts @@ -25,6 +25,6 @@ describe('prompt', () => { process.stdin.emit('data', '') const answer = await promptPromise await cli.done() - expect(answer).to.equal('') + expect(answer).to.equal(undefined) }) })