Home Manual Reference Source
public class | source

Prompt

This services works as an abstraction of the prompt package in order to add support for Promises, fix some quirks regarding boolean options, customize the interface just once and, finally, integrate it withe Jimple.

Constructor Summary

Public Constructor
public

constructor(messagesPrefix: string)

Class constructor.

Method Summary

Public Methods
public

ask(schema: Object): Promise<Object, Error>

Invoke the prompt package and ask the user for input.

public

getValue(property: string): string

Get a property value from the history.

public

history(property: string): Object

Access the history of the prompt.

Public Constructors

public constructor(messagesPrefix: string) source

Class constructor.

Params:

NameTypeAttributeDescription
messagesPrefix string
  • optional
  • default: ''

A prefix text that will be shown before each message.

Public Methods

public ask(schema: Object): Promise<Object, Error> source

Invoke the prompt package and ask the user for input.

Params:

NameTypeAttributeDescription
schema Object

The input data schema. For more information on how to build it, you should check the prompt package documentation, it's pretty complete. IMPORTANT: On the prompt documentation, this object would be the properties inside their schema object.

Return:

Promise<Object, Error>

If everything goes well, the resolved value is an object with the values the user entered; and if the user cancels the input, you'll get an error with the message canceled.

public getValue(property: string): string source

Get a property value from the history.

Params:

NameTypeAttributeDescription
property string

The name of the property.

Return:

string (nullable: true)

If the property is on the history, it will return its value, otherwise it will return undefined.

public history(property: string): Object source

Access the history of the prompt.

Params:

NameTypeAttributeDescription
property string

The name of the property you want to look on the history.

Return:

Object (nullable: true)

If the property is present, it will return an object with the name as property and its value, otherwise it will return undefined.