Documentation
¶
Index ¶
- Constants
- func NewProgressLog(lines int, prefix, title, header string) *progressLog
- func PushInterruptHandler(h InterruptHandler) func()
- type Asker
- type AskerConsole
- func (c *AskerConsole) Confirm(ctx context.Context, options ConsoleOptions) (bool, error)
- func (c *AskerConsole) DoInteraction(action func() error) error
- func (c *AskerConsole) EnsureBlankLine(ctx context.Context)
- func (c *AskerConsole) GetFormatter() output.Formatter
- func (c *AskerConsole) GetWriter() io.Writer
- func (c *AskerConsole) Handles() ConsoleHandles
- func (c *AskerConsole) IsNoPromptMode() bool
- func (c *AskerConsole) IsSpinnerInteractive() bool
- func (c *AskerConsole) IsSpinnerRunning(ctx context.Context) bool
- func (c *AskerConsole) IsUnformatted() bool
- func (c *AskerConsole) Message(ctx context.Context, message string)
- func (c *AskerConsole) MessageUxItem(ctx context.Context, item ux.UxItem)
- func (c *AskerConsole) MultiSelect(ctx context.Context, options ConsoleOptions) ([]string, error)
- func (c *AskerConsole) Prompt(ctx context.Context, options ConsoleOptions) (string, error)
- func (c *AskerConsole) PromptDialog(ctx context.Context, dialog PromptDialog) (map[string]any, error)
- func (c *AskerConsole) PromptFs(ctx context.Context, options ConsoleOptions, fsOpts FsOptions) (string, error)
- func (c *AskerConsole) Select(ctx context.Context, options ConsoleOptions) (int, error)
- func (c *AskerConsole) SetWriter(writer io.Writer)
- func (c *AskerConsole) ShowPreviewer(ctx context.Context, options *ShowPreviewerOptions) io.Writer
- func (c *AskerConsole) ShowSpinner(ctx context.Context, title string, format SpinnerUxType)
- func (c *AskerConsole) StopPreviewer(ctx context.Context, keepLogs bool)
- func (c *AskerConsole) StopSpinner(ctx context.Context, lastMessage string, format SpinnerUxType)
- func (c *AskerConsole) SupportsPromptDialog() bool
- func (c *AskerConsole) WaitForEnter()
- func (c *AskerConsole) WarnForFeature(ctx context.Context, key alpha.FeatureId)
- type Console
- type ConsoleHandles
- type ConsoleOptions
- type ConsoleShim
- type ExternalPromptConfiguration
- type FsOptions
- type FsSuggestOptions
- type InputSource
- type InputSourceKind
- type InterruptHandler
- type PromptDialog
- type PromptDialogChoice
- type PromptDialogItem
- type PromptRequiredError
- type RequiredInput
- type ShowPreviewerOptions
- type SpinnerUxType
- type TerminalWidthFn
- type Writers
Constants ¶
const DefaultPromptRequiredMessage = "This command cannot continue (interactive prompts disabled)"
DefaultPromptRequiredMessage is the default headline used when a command cannot continue without prompting.
Variables ¶
This section is empty.
Functions ¶
func NewProgressLog ¶
NewProgressLog returns a new instance of a progressLog.
func PushInterruptHandler ¶ added in v1.24.3
func PushInterruptHandler(h InterruptHandler) func()
PushInterruptHandler registers a handler to be invoked on the next SIGINT (Ctrl+C). Handlers are stacked: the most recently pushed handler runs first.
The returned function pops the handler from the stack and must be called to restore the previous interrupt behavior (typically with `defer`).
Types ¶
type AskerConsole ¶
type AskerConsole struct {
// contains filtered or unexported fields
}
func (*AskerConsole) Confirm ¶
func (c *AskerConsole) Confirm(ctx context.Context, options ConsoleOptions) (bool, error)
Prompts the user to confirm an operation
func (*AskerConsole) DoInteraction ¶
func (c *AskerConsole) DoInteraction(action func() error) error
func (*AskerConsole) EnsureBlankLine ¶
func (c *AskerConsole) EnsureBlankLine(ctx context.Context)
func (*AskerConsole) GetFormatter ¶
func (c *AskerConsole) GetFormatter() output.Formatter
func (*AskerConsole) GetWriter ¶
func (c *AskerConsole) GetWriter() io.Writer
Gets the underlying writer for the console
func (*AskerConsole) Handles ¶
func (c *AskerConsole) Handles() ConsoleHandles
func (*AskerConsole) IsNoPromptMode ¶
func (c *AskerConsole) IsNoPromptMode() bool
func (*AskerConsole) IsSpinnerInteractive ¶
func (c *AskerConsole) IsSpinnerInteractive() bool
func (*AskerConsole) IsSpinnerRunning ¶
func (c *AskerConsole) IsSpinnerRunning(ctx context.Context) bool
func (*AskerConsole) IsUnformatted ¶
func (c *AskerConsole) IsUnformatted() bool
func (*AskerConsole) Message ¶
func (c *AskerConsole) Message(ctx context.Context, message string)
Prints out a message to the underlying console write
func (*AskerConsole) MessageUxItem ¶
func (c *AskerConsole) MessageUxItem(ctx context.Context, item ux.UxItem)
func (*AskerConsole) MultiSelect ¶
func (c *AskerConsole) MultiSelect(ctx context.Context, options ConsoleOptions) ([]string, error)
func (*AskerConsole) Prompt ¶
func (c *AskerConsole) Prompt(ctx context.Context, options ConsoleOptions) (string, error)
Prompts the user for a single value
func (*AskerConsole) PromptDialog ¶
func (c *AskerConsole) PromptDialog(ctx context.Context, dialog PromptDialog) (map[string]any, error)
PromptDialog prompts for multiple values using a single dialog. When successful, it returns a map of prompt IDs to their values.
func (*AskerConsole) PromptFs ¶
func (c *AskerConsole) PromptFs(ctx context.Context, options ConsoleOptions, fsOpts FsOptions) (string, error)
PromptFs prompts the user for a filesystem path or directory
func (*AskerConsole) Select ¶
func (c *AskerConsole) Select(ctx context.Context, options ConsoleOptions) (int, error)
Prompts the user to select from a set of values
func (*AskerConsole) SetWriter ¶
func (c *AskerConsole) SetWriter(writer io.Writer)
Sets the underlying writer for output the console or if writer is nil, sets it back to the default writer.
func (*AskerConsole) ShowPreviewer ¶
func (c *AskerConsole) ShowPreviewer(ctx context.Context, options *ShowPreviewerOptions) io.Writer
func (*AskerConsole) ShowSpinner ¶
func (c *AskerConsole) ShowSpinner(ctx context.Context, title string, format SpinnerUxType)
func (*AskerConsole) StopPreviewer ¶
func (c *AskerConsole) StopPreviewer(ctx context.Context, keepLogs bool)
func (*AskerConsole) StopSpinner ¶
func (c *AskerConsole) StopSpinner(ctx context.Context, lastMessage string, format SpinnerUxType)
func (*AskerConsole) SupportsPromptDialog ¶
func (c *AskerConsole) SupportsPromptDialog() bool
func (*AskerConsole) WarnForFeature ¶
func (c *AskerConsole) WarnForFeature(ctx context.Context, key alpha.FeatureId)
type Console ¶
type Console interface {
// Prints out a message to the underlying console write
Message(ctx context.Context, message string)
// Prints out a message following a contract ux item
MessageUxItem(ctx context.Context, item ux.UxItem)
WarnForFeature(ctx context.Context, id alpha.FeatureId)
// Prints progress spinner with the given title.
// If a previous spinner is running, the title is updated.
ShowSpinner(ctx context.Context, title string, format SpinnerUxType)
// Stop the current spinner from the console and change the spinner bar for the lastMessage
// Set lastMessage to empty string to clear the spinner message instead of a displaying a last message
// If there is no spinner running, this is a no-op function
StopSpinner(ctx context.Context, lastMessage string, format SpinnerUxType)
// Preview mode brings an embedded console within the current session.
// Use nil for options to use defaults.
// Use the returned io.Writer to produce the output within the previewer
ShowPreviewer(ctx context.Context, options *ShowPreviewerOptions) io.Writer
// Finalize the preview mode from console.
StopPreviewer(ctx context.Context, keepLogs bool)
// Determines if there is a current spinner running.
IsSpinnerRunning(ctx context.Context) bool
// Determines if the current spinner is an interactive spinner, where messages are updated periodically.
// If false, the spinner is non-interactive, which means messages are rendered as a new console message on each
// call to ShowSpinner, even when the title is unchanged.
IsSpinnerInteractive() bool
// IsNoPromptMode returns true when --no-prompt is active and interactive prompts are disabled.
IsNoPromptMode() bool
SupportsPromptDialog() bool
PromptDialog(ctx context.Context, dialog PromptDialog) (map[string]any, error)
// Prompts the user for a single value
Prompt(ctx context.Context, options ConsoleOptions) (string, error)
// PromptFs prompts the user for a filesystem path or directory.
PromptFs(ctx context.Context, options ConsoleOptions, fsOptions FsOptions) (string, error)
// Prompts the user to select a single value from a set of values
Select(ctx context.Context, options ConsoleOptions) (int, error)
// Prompts the user to select zero or more values from a set of values
MultiSelect(ctx context.Context, options ConsoleOptions) ([]string, error)
// Prompts the user to confirm an operation
Confirm(ctx context.Context, options ConsoleOptions) (bool, error)
// block terminal until the next enter
WaitForEnter()
// Writes a new line to the writer if there if the last two characters written are not '\n'
EnsureBlankLine(ctx context.Context)
// Sets the underlying writer for the console
SetWriter(writer io.Writer)
// Gets the underlying writer for the console
GetWriter() io.Writer
// Gets the standard input, output and error stream
Handles() ConsoleHandles
// Executes an interactive action, managing spinner state
DoInteraction(action func() error) error
ConsoleShim
}
func NewConsole ¶
func NewConsole( noPrompt bool, isTerminal bool, writers Writers, handles ConsoleHandles, formatter output.Formatter, externalPromptCfg *ExternalPromptConfiguration) Console
Creates a new console with the specified writers, handles and formatter. When externalPromptCfg is non nil, it is used instead of prompting on the console.
type ConsoleHandles ¶
type ConsoleOptions ¶
type ConsoleShim ¶
type ConsoleShim interface {
// True if the console was instantiated with no format options.
IsUnformatted() bool
// Gets the underlying formatter used by the console
GetFormatter() output.Formatter
}
A shim to allow a single Console construction in the application. To be removed once formatter and Console's responsibilities are reconciled
type ExternalPromptConfiguration ¶
type ExternalPromptConfiguration struct {
Endpoint string
Key string
Transporter policy.Transporter
// NoPromptDialog when true, disables the prompt dialog feature even when external prompting is enabled.
// This causes each prompt to be sent individually through the external prompt API, which is useful
// for clients that don't support the dialog API but still want location prompts to include the full
// list of available locations.
NoPromptDialog bool
}
ExternalPromptConfiguration allows configuring the console to delegate prompts to an external service.
type FsOptions ¶
type FsOptions struct {
// Root directory.
Root string
// Path suggestion options.
SuggestOpts FsSuggestOptions
}
FsOptions provides options for prompting a filesystem path or directory.
type FsSuggestOptions ¶
type FsSuggestOptions struct {
// Exclude the current directory './' in suggestions. Only applicable if displaying directories.
ExcludeCurrentDir bool
// Include hidden files in suggestions.
IncludeHiddenFiles bool
// Exclude directories from suggestions.
ExcludeDirectories bool
// Exclude files from suggestions.
ExcludeFiles bool
}
FsSuggestOptions provides options for listing filesystem suggestions.
type InputSource ¶ added in v1.24.2
type InputSource struct {
Kind InputSourceKind `json:"kind"`
Name string `json:"name"`
ExampleValue string `json:"exampleValue,omitempty"`
}
InputSource describes one way a required input can be supplied.
type InputSourceKind ¶ added in v1.24.2
type InputSourceKind string
InputSourceKind identifies the kind of source that can satisfy a required input.
const ( InputSourceFlag InputSourceKind = "flag" InputSourceEnvironment InputSourceKind = "environment" InputSourceConfig InputSourceKind = "config" )
type InterruptHandler ¶ added in v1.24.3
type InterruptHandler func() (handled bool)
InterruptHandler is invoked when the user presses Ctrl+C.
Implementations are expected to drive any user interaction (such as confirming whether to abort an in-flight Azure operation) and return only after they have decided how to respond. The handler runs synchronously on a dedicated goroutine: any additional Ctrl+C signals received while the handler is running are ignored.
If the returned bool is false, the default azd interrupt behavior runs after the handler returns (the spinner is stopped and the process exits with code 1). Returning true tells the runtime that the handler took ownership of the shutdown sequence.
func SnapshotInterruptStack ¶ added in v1.24.3
func SnapshotInterruptStack() []InterruptHandler
SnapshotInterruptStack returns a copy of the current interrupt-handler stack in push order (oldest first). This exists exclusively to let tests in other packages observe and invoke the handler that they pushed via PushInterruptHandler without having to install the real OS signal pipeline.
It is NOT a stable API and must not be used by production code.
type PromptDialog ¶
type PromptDialog struct {
Title string
Description string
Prompts []PromptDialogItem
}
type PromptDialogChoice ¶
type PromptDialogItem ¶
type PromptRequiredError ¶ added in v1.24.2
type PromptRequiredError struct {
// Inputs is the list of required inputs that are missing.
Inputs []RequiredInput
// Message is the headline used for structured missing-input output.
Message string
// PromptMessage is the prompt text that would have been displayed to the user if interactive prompts were allowed.
PromptMessage string
}
PromptRequiredError is returned when --no-prompt mode prevents collecting required inputs interactively.
Either Inputs or PromptMessage is set, but not both.
func (*PromptRequiredError) Error ¶ added in v1.24.2
func (e *PromptRequiredError) Error() string
Error implements the error interface.
func (*PromptRequiredError) MarshalJSON ¶ added in v1.24.2
func (e *PromptRequiredError) MarshalJSON() ([]byte, error)
MarshalJSON implements json.Marshaler.
func (*PromptRequiredError) ToString ¶ added in v1.24.2
func (e *PromptRequiredError) ToString(currentIndentation string) string
ToString returns a formatted message with the missing inputs and short remediation guidance.
type RequiredInput ¶ added in v1.24.2
type RequiredInput struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
Sources []InputSource `json:"sources,omitempty"`
}
RequiredInput describes a missing input and the supported sources that can provide it.
type ShowPreviewerOptions ¶
ShowPreviewerOptions provide the settings to start a console previewer.
type SpinnerUxType ¶
type SpinnerUxType int
const ( Step SpinnerUxType = iota StepDone StepFailed StepWarning StepSkipped )
func GetStepResultFormat ¶
func GetStepResultFormat(result error) SpinnerUxType
type TerminalWidthFn ¶
type TerminalWidthFn func() int