smartcli/ts/smartcli.classes.interaction.ts

60 lines
1.2 KiB
TypeScript
Raw Normal View History

2016-10-14 22:56:02 +00:00
import * as plugins from './smartcli.plugins'
2016-06-13 10:56:42 +00:00
2016-08-26 09:52:09 +00:00
/**
* allows to specify an user interaction during runtime
*/
2016-10-14 22:56:02 +00:00
export type questionType = 'input' | 'confirm' | 'list' | 'rawlist' | 'expand' | 'checkbox' | 'password' | 'editor'
export interface IChoiceObject {
name: string
2016-08-26 09:52:09 +00:00
value: any
}
2016-10-14 22:56:02 +00:00
export interface IValidateFunction {
(any): boolean
2016-08-26 09:52:09 +00:00
}
export class Interaction {
constructor() {
2016-10-14 22:56:02 +00:00
}
2016-08-26 09:52:09 +00:00
askQuestion(optionsArg: {
type: questionType,
message: string
default: any
2016-10-14 22:56:02 +00:00
choices: string[] | IChoiceObject[]
validate: IValidateFunction
2016-08-26 09:52:09 +00:00
}) {
2016-10-14 22:56:02 +00:00
let done = plugins.q.defer()
2016-08-26 09:52:09 +00:00
plugins.inquirer.prompt([{
type: optionsArg.type,
message: optionsArg.message,
default: optionsArg.default,
2016-10-14 22:56:02 +00:00
choices: optionsArg.choices,
2016-08-26 09:52:09 +00:00
validate: optionsArg.validate
}]).then(answers => {
2016-10-14 22:56:02 +00:00
done.resolve(answers)
})
}
2016-08-26 09:52:09 +00:00
askQuestionArray
}
export class QuestionTree {
constructor(questionString: string, optionsArray) {
2016-10-14 22:56:02 +00:00
}
}
2016-08-26 09:52:09 +00:00
export class QuestionTreeNode {
constructor() {
}
2016-10-14 22:56:02 +00:00
}
2016-08-26 09:52:09 +00:00
export class QuestionStorage {
constructor() {
2016-06-16 00:58:45 +00:00
}
2016-10-14 22:56:02 +00:00
}