Skip to content

Commit

Permalink
fix(prompt): types
Browse files Browse the repository at this point in the history
  • Loading branch information
cenk1cenk2 committed Jun 3, 2020
1 parent 3e1c076 commit 110130a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
22 changes: 19 additions & 3 deletions examples/get-user-input.example.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/* eslint-disable @typescript-eslint/no-empty-function */
import Enquirer from 'enquirer'

import { Listr } from '../src/index'
import { Logger } from '@utils/logger'

Expand All @@ -18,10 +20,24 @@ async function main (): Promise<void> {
title: 'This task will get your input.',
task: async (ctx, task): Promise<Record<string, boolean>> => ctx.input = await task.prompt<{ test: boolean, other: boolean }>([
{
type: 'Toggle', name: 'test', message: 'test input?'
type: 'Select',
name: 'first',
message: 'Please select something',
choices: [ 'A', 'B', 'C' ],
validate: (response): boolean | string => {
// i do declare you valid!
if (response === 'A') {
return true
}
}
},
{
type: 'Toggle', name: 'other', message: 'other input?'
type: 'Input',
name: 'second',
message: 'Please type something in:',
skip: (answers: { first: string }): boolean => {
return answers.first === 'A'
}
}
])
},
Expand All @@ -34,7 +50,7 @@ async function main (): Promise<void> {
persistentOutput: true
}
}
], { concurrent: false })
], { concurrent: false, renderer: 'verbose' as 'default' })

try {
const context = await task.run()
Expand Down
12 changes: 6 additions & 6 deletions src/utils/prompt.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ interface BasePromptOptions {
message: string | (() => string) | (() => Promise<string>)
initial?: boolean | number | string | (() => string) | (() => Promise<string>)
required?: boolean
skip?: ((state: object) => boolean | Promise<boolean>) | boolean
stdin?: NodeJS.ReadStream
stdout?: NodeJS.WriteStream
format?(value: any): any | Promise<any>
result?(value: any): any | Promise<any>
validate?(value: any): boolean | Promise<boolean> | string | Promise<string>
onSubmit?(name: any, value: any, prompt: Enquirer.Prompt): boolean | Promise<boolean>
onCancel?(name: any, value: any, prompt: Enquirer.Prompt): boolean | Promise<boolean>
skip? (value: any): boolean | Promise<boolean>
format? (value: any): any | Promise<any>
result? (value: any): any | Promise<any>
validate? (value: any, state: any): boolean | Promise<boolean> | string | Promise<string>
onSubmit? (name: any, value: any, prompt: Enquirer.Prompt): boolean | Promise<boolean>
onCancel? (name: any, value: any, prompt: Enquirer.Prompt): boolean | Promise<boolean>
}

interface BasePromptOptionsWithName extends BasePromptOptions {
Expand Down

0 comments on commit 110130a

Please sign in to comment.