Interactive prompts

For accepting input, if stdin is a tty then prompt rather than forcing the user to specify a flag. Never require a prompt though. The user needs to be able to automate the CLI in a script so allow them to override prompts always.

Before executing the command, display what it looks like, to help the users learn how to use the CLI without the prompt.

E.g (the command following the interactive prompt shown below, huge thanks to Amy, working on MAAS UX for the awesome prototype)

$ maas deploy machine-name os=ubuntu release=18.04

Interactive prompts

Question objects containing question related values.

  • defaults: (String | Number | Boolean | Array | Function)
    Default value(s) are used when nothing is entered or the function returns the default value(s).

  • validate: (Function) Should return true if the value is valid, and an error message (String) otherwise. If false is returned, a default error message is provided.

Prompt type

  1. list
    Questions with a list of items for a user to select will contain the question and choices with optional default properties.

Optional enhancement: autocomplete - presents a list of option as the user types and display the nearest neighbours in the list as they type.

When a user typed the wrong argument, the prompt can suggest the nearest neighbour based on the input string.

  1. input
    When the prompt requires a user to add input in a certain format, it will contain the question and receives input with optional default or validate properties.

Some input format might require validation before proceeding such as datetime input, number input, etc.

For instance, the input prompt that requires a number input might need to validate that an input is a valid number before submitting. If an input is not a number, it will print an error message.

Screen Shot 2021-03-19 at 5.04.35 PM

  1. confirm
    When a prompt is asking for a yes or no answer, it is recommended to have a default answer as part of the question, even though default is an optional choice.

For instance

>  Register MAAS as KVM host [default = no] : (y/N)

Reference:
The prototype in this example uses inquirerJS to prototype the interactive prompts.

2 Likes

Is this the same guideline for yes/no answers? Like snapcraft register

There was a [default=No] prompt in the demo.
Though what library would be used to provide the interactive menuing being shown is interesting. Is there a common ncurses that would give similar results in both Python and Go?

1 Like

This is certainly very pretty, it would be interesting to have libraries in all of our common languages to provide the infrastructure (output a prompt with a menu list of items you could chose from).