Go SDK: prompts

Prompt interface overview

The following Prompts are supported by the Golang SDK:

  • Checkbox
  • Confirm
  • Datetime
  • Editor
  • Input
  • List
  • Number
  • Password
  • Secret

To create a prompt in your Pipeline or Command, you need to create a new Prompt object (whose methods are the above listed supported Prompts):

Alternatively, the Prompt object is included in the Client object:

func (*Prompt) Checkbox

func (*Prompt) Checkbox(name, msg string, choices []string, options ...CheckboxOption) ([]string, error)

Checkbox presents a list of options to the user, who can select multiple items in the interface (i.e. terminal or Slack).

choices is the list of string options that can be selected.

Example:

Output:

Type:

type CheckboxOption func(*daemon.CheckboxPromptBody)

func OptCheckboxDefaultIndex

func OptCheckboxDefaultIndex(defaultIndexes []int) CheckboxOption

func OptCheckboxDefaultValues

func OptCheckboxDefaultValues(defaultValues []string) CheckboxOption

func OptCheckboxFlag

func OptCheckboxFlag(flag string) CheckboxOption

OptCheckboxFlag sets the flag value for the checkbox prompt. The flag value is used to match the command line arguments to prompts.

func (*Prompt) Confirm

func (*Prompt) Confirm(name, msg string, options ...ConfirmOption) (bool, error)

Confirm presents a yes/no question to the user in the interface (i.e. terminal or Slack).

Example:

Output:

Type:

type ConfirmOption func(*daemon.ConfirmPromptBody)

func OptConfirmDefault

func OptConfirmDefault(defaultValue bool) ConfirmOption

func OptConfirmFlag

func OptConfirmFlag(flag string) ConfirmOption

OptConfirmFlag sets the flag value for the confirm prompt. The flag value is used to match command line arguments to prompts.

func (*Prompt) Datetime

func (*Prompt) Datetime(name, msg string, options ...DatetimeOption) (time.Time, error)

Datetime presents a date picker to the user that allows them to select a date and/or time. The method returns the user’s response as a time.Time type.

Example:

Output:

Type:

type DatetimeOption func(*daemon.DatetimePromptBody)

func OptDatetimeDefault

func OptDatetimeDefault(defaultValue time.Time) DatetimeOption

func OptDatetimeFlag

func OptDatetimeFlag(flag string) DatetimeOption

OptDatetimeFlag sets the flag value for the datetime prompt. The flag value is used to match the command line arguments to prompts.

func OptDatetimeMaximum

func OptDatetimeMaximum(maximumValue time.Time) DatetimeOption

func OptDatetimeMinimum

func OptDatetimeMinimum(minimumValue time.Time) DatetimeOption

func OptDatetimeVariant

func OptDatetimeVariant(variant string) DatetimeOption

func (*Prompt) Editor

func (*Prompt) Editor(name, msg string, options ...EditorOption) (string, error)

Editor presets a prompt requesting a multi-line response from the user. If used in a terminal interface, the nano editor will be presented.

Example:

Output:

Type:

type EditorOption func(*daemon.EditorPromptBody)

func OptEditorDefault

func OptEditorDefault(defaultValue string) EditorOption

func OptEditorFlag

func OptEditorFlag(flag string) EditorOption

OptEditorFlag sets the flag value for the editor prompt. The flag value is used to match command line arguments to prompts.

func (*Prompt) Input

func (*Prompt) Input(name, msg string, options ...InputOption) (string, error)

Input presents an input (single-line text) prompt on the interface (i.e. terminal or Slack).

The method returns the user’s response as string.

Example:

Output:

Type:

type InputOption func(*daemon.InputPromptBody)

func OptInputAllowEmpty

func OptInputAllowEmpty(allowEmpty bool) InputOption

OptInputAllowEmpty sets whether the input prompt should accept an empty line. Has no effect if a default is set.

func OptInputDefault

func OptInputDefault(defaultValue string) InputOption

OptInputDefault sets the default value for the input prompt.

func OptInputFlag

func OptInputFlag(flag string) InputOption

OptInputFlag sets the flag value for the input prompt. The flag value is used to match command line arguments to prompts.

func (*Prompt) List

func (*Prompt) List(name, msg string, choices []string, options ...ListOption) (string, error)

List presents a list of options to the user to select one item from in the interface (i.e. terminal or Slack).

choices is the list of string options that can be selected.

Example:

Output:

Type:

type ListOption func(*daemon.ListPromptBody)

func OptListAutocomplete

func OptListAutocomplete(autocomplete bool) ListOption

func OptListDefaultIndex

func OptListDefaultIndex(defaultIndex int) ListOption

func OptListDefaultValue

func OptListDefaultValue(defaultValue string) ListOption

func OptListFlag

func OptListFlag(flag string) ListOption

OptListFlag sets the flag value for the list prompt. The flag value is used to match command line arguments to prompts.

func (*Prompt) Number

func (*Prompt) Number(name, msg string, options ...NumberOption) (int, error)

Number presents a prompt for a numeric value to the interface (i.e. terminal or Slack).

The method returns the user’s response as int.

Example:

Output:

Type:

type NumberOption func(*daemon.NumberPromptBody)

func OptNumberDefault

func OptNumberDefault(defaultValue int) NumberOption

func OptNumberFlag

func OptNumberFlag(flag string) NumberOption

OptNumberFlag sets the flag value for the number prompt. The flag value is used to match command line arguments to prompts.

func OptNumberMaximum

func OptNumberMaximum(maximumValue int) NumberOption

func OptNumberMinimum

func OptNumberMinimum(minimumValue int) NumberOption

func (*Prompt) Password

func (*Prompt) Password(name, msg string, options ...PasswordOption) (string, error)

Password presents an input prompt for passwords in the interface (i.e. terminal or Slack).

The password can be entered by the user or selected from their team’s secret store. If the value is entered directly, it will be obscured on the screen.

For passwords, the name doubles as the default secret store key for the desired secret. If this key is present, it will be selected as the default option for the user.

The method returns the user’s response as string.

Example:

Output:

Type:

type PasswordOption func(*daemon.PasswordPromptBody)

func OptPasswordConfirm

func OptPasswordConfirm(confirm bool) PasswordOption

func OptPasswordFlag

func OptPasswordFlag(flag string) PasswordOption

OptPasswordFlag sets the flag value for the password prompt. The flag value is used to match command line arguments to prompts.

func (*Prompt) Secret

func (*Prompt) Secret(name, msg string, options ...SecretOption) (string, error)

Secret presents an input prompt for secrets in the interface (i.e. terminal or Slack).

The secret can be entered by the user or selected from their team’s secret store. The value will be displayed on the terminal/screen as it is entered for verification

For secrets, the name doubles as the default secret store key for the desired secret. If this key is present, it will be selected as the default option for the user.

The method returns the user’s response as string.

Example:

Output:

Type:

type SecretOption func(*daemon.SecretPromptBody)

func OptSecretFlag

func OptSecretFlag(flag string) SecretOption

OptSecretFlag sets the flag value for the secret prompt. The flag value is used to match command line arguments to prompts.