cli

package
v0.5.8 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2018 License: BSD-3-Clause Imports: 7 Imported by: 4

Documentation

Overview

Command, OptionInfo, help and command execution pattern derived from github.com/constabulary/gb, released under MIT license https://github.com/constabulary/gb/blob/master/LICENSE

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CmdUsage

func CmdUsage(toolName string, command Command)

CmdUsage prints the usage details of the specified Command and exits with error

func ExecCommand

func ExecCommand(fs *flag.FlagSet, cmd Command, args []string) error

ExecCommand executes the specified command

func PrintCmdHelp

func PrintCmdHelp(toolName string, command Command)

PrintCmdHelp prints the help details of the specified Command

func PrintCmdUsage

func PrintCmdUsage(w io.Writer, toolName string, command Command)

PrintCmdUsage prints the usage details of the specified Command

func RegisterTool

func RegisterTool(tool *Tool)

RegisterTool registers the provided tool

Types

type Command

type Command interface {
	HasOptionInfo

	AddFlags(fs *flag.FlagSet)

	Exec(args []string) error
}

Command represents a command that is executed within flogo project Derived from github.com/constabulary/gb

type CommandRegistry

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

CommandRegistry is a registry for commands

func NewCommandRegistry

func NewCommandRegistry() *CommandRegistry

NewCommandRegistry creates a new command registry

func (*CommandRegistry) Command

func (r *CommandRegistry) Command(commandName string) (cmd Command, exists bool)

Command gets the specified command

func (*CommandRegistry) CommandOptionInfos

func (r *CommandRegistry) CommandOptionInfos() []*OptionInfo

CommandOptionInfos gets the OptionInfos for all registered commands

func (*CommandRegistry) Commands

func (r *CommandRegistry) Commands() []Command

Commands gets all the registered commands

func (*CommandRegistry) RegisterCommand

func (r *CommandRegistry) RegisterCommand(command Command)

RegisterCommand registers a command

type HasOptionInfo

type HasOptionInfo interface {
	OptionInfo() *OptionInfo
}

HasOptionInfo is an interface for an object that has Option Information

type OptionInfo

type OptionInfo struct {
	// Denotes if tool or command
	IsTool bool

	// Name of the tool/command
	Name string

	// UsageLine demonstrates how to invoke the tool/command
	UsageLine string

	// Short description of tool/command
	Short string

	// Description of this tool/command
	Long string
}

OptionInfo is the option information for a command

func GetToolOptionInfos

func GetToolOptionInfos() []*OptionInfo

GetToolOptionInfos gets all the OptionInfos for the registered tools

type Tool

type Tool struct {
	TplUsage    string
	TplCmdUsage string
	TplCmdHelp  string
	// contains filtered or unexported fields
}

Tool is a

func GetTool

func GetTool(toolName string) (tool *Tool, exists bool)

GetTool returns the specified tool

func GetTools

func GetTools() []*Tool

GetTools gets all the registered tools

func NewTool

func NewTool(optionInfo *OptionInfo) *Tool

NewTool creates a new tool

func (*Tool) CmdUsage

func (t *Tool) CmdUsage(command Command)

CmdUsage prints the usage details of the specified Command and exits with error

func (*Tool) CommandRegistry

func (t *Tool) CommandRegistry() *CommandRegistry

CommandRegistry gets the command registry for the tool

func (*Tool) OptionInfo

func (t *Tool) OptionInfo() *OptionInfo

OptionInfo implements HasOptionInfo

func (*Tool) PrintCmdHelp

func (t *Tool) PrintCmdHelp(command Command)

PrintCmdHelp prints the help details of the specified Command

func (*Tool) PrintCmdUsage

func (t *Tool) PrintCmdUsage(w io.Writer, command Command)

PrintCmdUsage prints the usage details of the specified Command

func (*Tool) PrintUsage

func (t *Tool) PrintUsage(w io.Writer)

PrintUsage prints the usage details of the tool

func (*Tool) Usage

func (t *Tool) Usage()

Usage prints the usage details of the tool and exits with error

Jump to

Keyboard shortcuts

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