actions

package
v0.0.0-...-ba6934c Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

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

Index

Constants

This section is empty.

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
	// The logic that produces the command help
	HelpOptions ActionHelpOptions
	// Defines grouping options for the command
	GroupingOptions CommandGroupOptions
}

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 = ""
	CmdGroupConfig  RootLevelHelpOption = "Configure and develop your app"
	CmdGroupManage  RootLevelHelpOption = "Manage Azure resources and app deployments"
	CmdGroupMonitor RootLevelHelpOption = "Monitor, test and release your app"
	CmdGroupAbout   RootLevelHelpOption = "About, help and upgrade"
)

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