cli

package
v2.2.6 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2020 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package cli provides tools to create commands that support advanced configuration features, sub-commands, and allowing configuration from command-line flags, configuration files, and environment variables.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Execute

func Execute(cmd *Command) error

Execute Executes a command.

func PrintHelp

func PrintHelp(w io.Writer, cmd *Command) error

PrintHelp prints the help for the command given as argument.

Types

type Command

type Command struct {
	Name           string
	Description    string
	Configuration  interface{}
	Resources      []ResourceLoader
	Run            func([]string) error
	CustomHelpFunc func(io.Writer, *Command) error
	Hidden         bool
	// AllowArg if not set, disallows any argument that is not a known command or a sub-command.
	AllowArg bool
	// contains filtered or unexported fields
}

Command structure contains program/command information (command name and description).

func (*Command) AddCommand

func (c *Command) AddCommand(cmd *Command) error

AddCommand Adds a sub command.

func (*Command) PrintHelp added in v2.1.0

func (c *Command) PrintHelp(w io.Writer) error

PrintHelp calls the custom help function of the command if it's set. Otherwise, it calls the default help function.

type EnvLoader

type EnvLoader struct{}

EnvLoader loads a configuration from all the environment variables prefixed with "TRAEFIK_".

func (*EnvLoader) Load

func (e *EnvLoader) Load(_ []string, cmd *Command) (bool, error)

Load loads the command's configuration from the environment variables.

type FileLoader

type FileLoader struct {
	ConfigFileFlag string
	// contains filtered or unexported fields
}

FileLoader loads a configuration from a file.

func (*FileLoader) GetFilename

func (f *FileLoader) GetFilename() string

GetFilename returns the configuration file if any.

func (*FileLoader) Load

func (f *FileLoader) Load(args []string, cmd *Command) (bool, error)

Load loads the command's configuration from a file either specified with the -traefik.configfile flag, or from default locations.

type Finder

type Finder struct {
	BasePaths  []string
	Extensions []string
}

Finder holds a list of file paths.

func (Finder) Find

func (f Finder) Find(configFile string) (string, error)

Find returns the first valid existing file among configFile and the paths already registered with Finder.

type FlagLoader

type FlagLoader struct{}

FlagLoader loads configuration from flags.

func (*FlagLoader) Load

func (*FlagLoader) Load(args []string, cmd *Command) (bool, error)

Load loads the command's configuration from flag arguments.

type ResourceLoader

type ResourceLoader interface {
	// Load populates cmd.Configuration, optionally using args to do so.
	Load(args []string, cmd *Command) (bool, error)
}

ResourceLoader is a configuration resource loader.

Jump to

Keyboard shortcuts

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