Documentation
¶
Index ¶
- Variables
- func CommandExit(err error)
- func Execute(ctb CLIInterface)
- func ExecuteE(ctb CLIInterface) (err error)
- func GetExitOnError() bool
- func LogIfErr(err error, logger *log.Logger)
- func SetExitOnError(value bool)
- type CLIInterface
- type ConfigOutput
- type ContainerToolCommand
- type ContainerToolCommandBase
- func (ctb *ContainerToolCommandBase) AddCommand(command CLIInterface)
- func (ctb *ContainerToolCommandBase) AddFlags()
- func (ctb *ContainerToolCommandBase) AddSubCommands()
- func (ctb *ContainerToolCommandBase) Init()
- func (ctb *ContainerToolCommandBase) ReadTemplateFromFlagOrCmdDefault() string
- func (ctb *ContainerToolCommandBase) SetSilenceUsage()
- type ContainerToolListCommand
- type ListCommandOutputObject
- type UpdateCheckOutput
- type VersionOutput
Constants ¶
This section is empty.
Variables ¶
View Source
var ConfigCommand = &ContainerToolCommand{ ContainerToolCommandBase: &ContainerToolCommandBase{ Command: &cobra.Command{ Use: "config", Long: `Prints all Config Keys. This command evalues all the keys from Default Config and Tool Config and prints the final value`, Short: "Prints all Config Keys", Args: cobra.ExactArgs(0), }, DefaultTemplate: "{{ range $k, $v := .Config }}{{$k}} : {{$v}}\n{{ end }}", }, Output: &ConfigOutput{}, RunO: func(command *cobra.Command, args []string) (interface{}, error) { return &ConfigOutput{ Config: viper.AllSettings(), }, nil }, }
View Source
var ConfigFile string
View Source
var ConfigType = constants.ConfigType
View Source
var DownloadUrl = ""
View Source
var HelpTemplate = `
{{if or .Runnable .HasSubCommands}}{{.UsageString}}{{end}}`
View Source
var Log = &log.Logger{}
View Source
var ReleaseUrl = ""
View Source
var SetConfigCommand = &cobra.Command{ Use: "set", Long: `Sets the config Key and makes the change in the Tool Config File.`, Short: "Sets the config Key in the Tool Config", Args: cobra.ExactArgs(2), RunE: func(command *cobra.Command, args []string) error { _, exists := viper.AllSettings()[args[0]] if !exists { Log.Panicf("Config Key %s does not exist.", args[0]) } v := viper.New() v.SetConfigFile(ConfigFile) v.ReadInConfig() v.Set(args[0], args[1]) v.WriteConfig() logging.Out.Infof("Config key Changed and written to file %s", ConfigFile) return nil }, }
View Source
var UpdateCheck bool
View Source
var UpdateCheckCommand = &ContainerToolCommand{ ContainerToolCommandBase: &ContainerToolCommandBase{ Command: &cobra.Command{ Use: "updatecheck", Short: "Checks if an update is available", Long: `Checks if an update is available.`, Args: cobra.ExactArgs(0), }, DefaultTemplate: `{{if .CurrentVersion.EQ .LatestVersion }}You are at the latest Version. No updates Available.{{end}} {{if .CurrentVersion.LT .LatestVersion}}There is a newer version {{.LatestVersion}} of tool available. Download it here: {{.DownloadUrl}}{{end}}`, }, Output: &UpdateCheckOutput{}, RunO: func(command *cobra.Command, args []string) (interface{}, error) { if ReleaseUrl == "" { Log.Panicf("No ReleaseUrl defined. Cannot Check for Updates.") } latestVersion, err := notify.GetLatestVersionFromURL(ReleaseUrl, VersionPrefix) if err != nil { Log.Panic(err) } currentVersion, err := semver.Make(Version) if err != nil { Log.Panic(err) } var updateCheck = UpdateCheckOutput{ CurrentVersion: currentVersion, LatestVersion: latestVersion, DownloadUrl: DownloadUrl, } return updateCheck, nil }, }
View Source
var Version string
View Source
var VersionCommand = &ContainerToolCommand{ ContainerToolCommandBase: &ContainerToolCommandBase{ Command: &cobra.Command{ Use: "version", Short: "Print the version", Long: `Print the version`, Args: cobra.ExactArgs(0), }, DefaultTemplate: "{{.Version}}", }, Output: &VersionOutput{}, RunO: func(command *cobra.Command, args []string) (interface{}, error) { var versionOutput = VersionOutput{ Version: VersionPrefix + Version, } return versionOutput, nil }, }
View Source
var VersionPrefix = ""
Functions ¶
func CommandExit ¶
func CommandExit(err error)
func Execute ¶
func Execute(ctb CLIInterface)
func ExecuteE ¶
func ExecuteE(ctb CLIInterface) (err error)
func GetExitOnError ¶
func GetExitOnError() bool
func SetExitOnError ¶
func SetExitOnError(value bool)
Types ¶
type CLIInterface ¶
type CLIInterface interface { ValidateCommand() error Init() // contains filtered or unexported methods }
type ConfigOutput ¶
type ConfigOutput struct {
Config map[string]interface{}
}
type ContainerToolCommand ¶
type ContainerToolCommand struct { *ContainerToolCommandBase Output interface{} // RunO Executes cobra.Command.Run and returns an Output RunO func(command *cobra.Command, args []string) (interface{}, error) }
func (*ContainerToolCommand) ValidateCommand ¶
func (ctc *ContainerToolCommand) ValidateCommand() error
type ContainerToolCommandBase ¶
type ContainerToolCommandBase struct { *cobra.Command Phase string DefaultTemplate string //TODO: Validate Default Config. TemplateFuncMap template.FuncMap }
func (*ContainerToolCommandBase) AddCommand ¶
func (ctb *ContainerToolCommandBase) AddCommand(command CLIInterface)
func (*ContainerToolCommandBase) AddFlags ¶
func (ctb *ContainerToolCommandBase) AddFlags()
func (*ContainerToolCommandBase) AddSubCommands ¶
func (ctb *ContainerToolCommandBase) AddSubCommands()
func (*ContainerToolCommandBase) Init ¶
func (ctb *ContainerToolCommandBase) Init()
func (*ContainerToolCommandBase) ReadTemplateFromFlagOrCmdDefault ¶
func (ctb *ContainerToolCommandBase) ReadTemplateFromFlagOrCmdDefault() string
func (*ContainerToolCommandBase) SetSilenceUsage ¶
func (ctb *ContainerToolCommandBase) SetSilenceUsage()
type ContainerToolListCommand ¶
type ContainerToolListCommand struct { *ContainerToolCommandBase OutputList []interface{} // RunO Executes cobra.Command.Run and returns an List[Output] RunO func(command *cobra.Command, args []string) ([]interface{}, error) // When defined, StreamO Executes cobra.Command.Run and streams each item in the List as its added. // This will ignore the RunO function. StreamO func(command *cobra.Command, args []string) // This function will execute over the output list and return a Summary Object which can be printed. // The SummaryTemplate Field can be used to print the Object. TotalO func(list []interface{}) (interface{}, error) SummaryObject interface{} SummaryTemplate string // Defines the stream to write objects to when using StreamO Stream chan interface{} }
func (ContainerToolListCommand) ReadFromStream ¶
func (commandList ContainerToolListCommand) ReadFromStream(streamOutput bool) ([]interface{}, error)
func (*ContainerToolListCommand) ValidateCommand ¶
func (ctc *ContainerToolListCommand) ValidateCommand() error
type ListCommandOutputObject ¶
type ListCommandOutputObject struct { OutputList []interface{} SummaryObject interface{} }
type UpdateCheckOutput ¶
type VersionOutput ¶
type VersionOutput struct {
Version string
}
Source Files
¶
Click to show internal directories.
Click to hide internal directories.