Help us shape the future of Go! Take the 2026 Go Developer Survey

actions

package
v1.36.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 15, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package actions contains the application logic that handles azd CLI commands.

Index

Constants

View Source
const (

	// AnnotationLightspeed is a cobra annotation key that marks a command as lightspeed.
	// Lightspeed commands skip non-essential background work (update checks) so the
	// process can exit as fast as possible. Set automatically by CobraBuilder when
	// ActionDescriptorOptions.Lightspeed is true.
	AnnotationLightspeed = "azd.lightspeed"
)

Variables

This section is empty.

Functions

func GetGroupCommandAnnotation

func GetGroupCommandAnnotation(cmd *cobra.Command) (string, bool)

GetGroupCommandAnnotation check if there is a grouping annotation for the command. Returns the annotation value as an i18nTextId (so it can be used directly to resolve a string) if the annotation is found. Otherwise, returns `"", false` to indicate the command has no grouping annotation.

func SetGroupCommandAnnotation

func SetGroupCommandAnnotation(cmd *cobra.Command, group RootLevelHelpOption)

Types

type Action

type Action interface {
	// Run executes the CLI command.
	//
	// It is currently valid to both return an error and a non-nil ActionResult.
	Run(ctx context.Context) (*ActionResult, error)
}

Action is the representation of the application logic of a CLI command.

type ActionDescriptor

type ActionDescriptor struct {
	// Name of the descriptor (also used for command name if not specified in options)
	Name string
	// Descriptor options
	Options *ActionDescriptorOptions
	// contains filtered or unexported fields
}

Action descriptors consolidates the registration for a cobra command and related flags, actions and help messages.

func NewActionDescriptor

func NewActionDescriptor(name string, options *ActionDescriptorOptions) *ActionDescriptor

Creates a new action descriptor

func (*ActionDescriptor) Add

Adds a child action descriptor with the specified name and options

func (*ActionDescriptor) AddFlagCompletion

func (ad *ActionDescriptor) AddFlagCompletion(flagName string, flagCompletionFn FlagCompletionFunc) *ActionDescriptor

Registers a cobra flag completion for the specified flag Flags are lazily evaluated and cannot be registered inline within the options

func (*ActionDescriptor) Children

func (ad *ActionDescriptor) Children() []*ActionDescriptor

Gets the child descriptors of the current instance

func (*ActionDescriptor) FlagCompletions

func (ad *ActionDescriptor) FlagCompletions() map[string]FlagCompletionFunc

Gets the cobra command flag completion registrations for the current instance

func (*ActionDescriptor) Middleware

func (ad *ActionDescriptor) Middleware() []*MiddlewareRegistration

Gets the middleware registrations for the current instance

func (*ActionDescriptor) Parent

func (ad *ActionDescriptor) Parent() *ActionDescriptor

Gets the parent descriptor of the current instance

func (*ActionDescriptor) UseMiddleware

func (ad *ActionDescriptor) UseMiddleware(name string, middlewareResolver any) *ActionDescriptor

Registers a middleware component to be run for this action and all child actions

func (*ActionDescriptor) UseMiddlewareWhen

func (ad *ActionDescriptor) UseMiddlewareWhen(
	name string,
	middlewareResolver any,
	predicate UseMiddlewareWhenPredicate,
) *ActionDescriptor

Registers a middleware component to be run for this action and all child actions when the specified predicate returns a truthy value

type ActionDescriptorOptions

type ActionDescriptorOptions struct {
	// Cobra command configuration
	*cobra.Command
	// Function to resolve / create the flags instance required for the action
	FlagsResolver any
	// Function to resolve / create the action instance
	ActionResolver any
	// Array of support output formats
	OutputFormats []output.Format
	// The default output format if omitted in the command flags
	DefaultFormat output.Format
	// Whether or not telemetry should be disabled for the current action
	DisableTelemetry bool
	// Whether or not troubleshooting should be disabled for the current action
	DisableTroubleshooting bool
	// The logic that produces the command help
	HelpOptions ActionHelpOptions
	// Defines grouping options for the command
	GroupingOptions CommandGroupOptions
	// Whether or not the command requires a principal login
	RequireLogin bool
	// Whether the command should execute as fast as possible, skipping
	// non-essential background work like update checks.
	// Use for programmatic/hidden commands (e.g., auth token) where
	// blocking process exit is unacceptable.
	Lightspeed bool
}

ActionDescriptionOptions specifies all options for a given azd command and action

type ActionFunc

type ActionFunc func(context.Context) (*ActionResult, error)

ActionFunc is an Action implementation for regular functions.

func (ActionFunc) Run

func (a ActionFunc) Run(ctx context.Context) (*ActionResult, error)

Run implements the Action interface

type ActionHelpGenerator

type ActionHelpGenerator func(cmd *cobra.Command) string

ActionHelpGenerator defines the signature for using a custom help text block for a command.

type ActionHelpOptions

type ActionHelpOptions struct {
	Description ActionHelpGenerator
	Usage       ActionHelpGenerator
	Commands    ActionHelpGenerator
	Flags       ActionHelpGenerator
	Footer      ActionHelpGenerator
}

ActionHelpOptions changes the default text that is displayed for command's help.

type ActionResult

type ActionResult struct {
	Message *ResultMessage
}

Define the Action outputs.

type CommandGroupOptions

type CommandGroupOptions struct {
	RootLevelHelp RootLevelHelpOption
}

CommandGroupOptions contains the grouping information that is set when building the command.

type FlagCompletionFunc

type FlagCompletionFunc func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective)

Completion function used for cobra command flag completion

type MiddlewareRegistration

type MiddlewareRegistration struct {
	// The name of the middleware used for logging purposes
	Name string
	// The constructor/resolver used to create the middleware instance
	Resolver any
	// An optional predicate to control when this middleware is registered
	Predicate UseMiddlewareWhenPredicate
}

MiddlewareRegistration allows middleware components to be registered at any level within the command hierarchy

type ResultMessage

type ResultMessage struct {
	Header   string
	FollowUp string
}

Define a message as the completion of an Action.

type RootLevelHelpOption

type RootLevelHelpOption string

RootLevelHelpOption describe a group where the command belongs. The types are later used by cmd package to annotate the command.

const (
	CmdGroupNone       RootLevelHelpOption = ""
	CmdGroupStart      RootLevelHelpOption = "Getting started"
	CmdGroupAzure      RootLevelHelpOption = "Create and manage Azure resources"
	CmdGroupBeta       RootLevelHelpOption = "Beta commands"
	CmdGroupAlpha      RootLevelHelpOption = "Enabled alpha commands"
	CmdGroupManage     RootLevelHelpOption = "Manage and show settings"
	CmdGroupExtensions RootLevelHelpOption = "Enabled extensions commands "
)

func GetGroupAnnotations

func GetGroupAnnotations() []RootLevelHelpOption

type UseMiddlewareWhenPredicate

type UseMiddlewareWhenPredicate func(descriptor *ActionDescriptor) bool

Predicate function used to evaluate middleware registrations

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL