cli

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2020 License: Apache-2.0 Imports: 13 Imported by: 9

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildCommand

func BuildCommand(name string, short string, long string, runFunc func(ctx Context) error) *cobra.Command

BuildCommand will construct a cobra command object with our version injected and a default Run method

func WaitForConfirmation

func WaitForConfirmation(message string) (bool, error)

WaitForConfirmation will print a message and prompt for a Y/N confirmation. It will return the confirmation value and and error if failing to read stdin.

Types

type Context

type Context struct {
	Args       []string
	Exec       exechelper.Executor
	Filesystem fshelper.FileSystem
	Config     *viper.Viper
	CmdContext interface{}
}

Context has all the context/config required for CLI command handlers to operate

type WorkFlowStep

type WorkFlowStep interface {
	// Run should run the method and *not* print anything on stdout, only logging
	Run(ctx Context) error
	// Text is the description or title or whatever we want to show to the user as we print progress through
	// the workflow.
	Text() string
	// Silent returns whether or not the step should be considered as silent (no Text() or progress will be shown)
	Silent() bool
}

WorkFlowStep defines a step in a CLI workflow with some helper to run the step and provide info in the UI (terminal, usually)

func NewNonTerminatingWorkflowStep

func NewNonTerminatingWorkflowStep(text string, fn func(ctx Context) error) WorkFlowStep

NewNonTerminatingWorkflowStep creates a new generic WorkFlowStep that runs the specified function and shows the text given.

func NewWorkflowStep

func NewWorkflowStep(text string, fn func(ctx Context) error) WorkFlowStep

NewWorkflowStep creates a new generic WorkFlowStep that runs the specified function and shows the text given.

type WorkflowEngine

type WorkflowEngine struct {
	// contains filtered or unexported fields
}

WorkflowEngine holds onto a series of workflow steps and can process them with error handling.

func NewWorkFlowEngine

func NewWorkFlowEngine(workflowSteps ...WorkFlowStep) *WorkflowEngine

NewWorkFlowEngine constructs a workflow engine instance with the specified workflows steps.

func (*WorkflowEngine) Run

func (w *WorkflowEngine) Run(ctx Context) error

Run will process the steps of the workflow executing the functions in order until finished or one func returns an error. On error the workflow is stopped and the error is returned. If the workflow succeeds the return value will be nil.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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