cmdhelper

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Init

func Init(cobraCommand *cobra.Command, contextVariables ContextVariables)
Example
cobraCommand := &cobra.Command{
	Use:   "example-use",
	Short: "example-short",
	Long:  `example-long`,
}
var contextVariables = ContextVariables{
	Strings: []ContextString{
		{
			Default: "",
			Envar:   "MY_VARIABLE",
			Help:    "Description of my variable [%s]",
			Option:  "my-variable",
		},
	},
}
Init(cobraCommand, contextVariables)

func InitBools

func InitBools(cobraCommand *cobra.Command, contextBools []ContextBool)

func InitInts

func InitInts(cobraCommand *cobra.Command, contextInts []ContextInt)

func InitStringSlices

func InitStringSlices(cobraCommand *cobra.Command, contextStringSlices []ContextStringSlice)

func InitStrings

func InitStrings(cobraCommand *cobra.Command, contextStrings []ContextString)

func OsLookupEnvBool

func OsLookupEnvBool(envar string, aDefault bool) bool
Example
fmt.Println(OsLookupEnvBool("NOT_AN_ENVIRONMENT_VARIABLE", true))
Output:

true

func OsLookupEnvInt

func OsLookupEnvInt(envar string, aDefault int) int
Example
fmt.Println(OsLookupEnvInt("NOT_AN_ENVIRONMENT_VARIABLE", 10))
Output:

10

func OsLookupEnvString

func OsLookupEnvString(envar string, aDefault string) string
Example
fmt.Println(OsLookupEnvString("NOT_AN_ENVIRONMENT_VARIABLE", "default"))
Output:

default

func PreRun

func PreRun(cobraCommand *cobra.Command, args []string, configName string, contextVariables ContextVariables)
Example
cobraCommand := &cobra.Command{
	Use:   "example-use",
	Short: "example-short",
	Long:  `example-long`,
}
var contextVariables = ContextVariables{
	Strings: []ContextString{
		{
			Default: "",
			Envar:   "MY_VARIABLE",
			Help:    "Description of my variable [%s]",
			Option:  "my-variable",
		},
	},
}
Init(cobraCommand, contextVariables)
PreRun(cobraCommand, []string{}, "example-cmd", contextVariables)

func Version

func Version(version string, iteration string) string
Example
result := Version("1.2.3", "4")
fmt.Println(result)
Output:

1.2.3-4

Types

type ContextBool

type ContextBool struct {
	Default bool   `json:"default"`
	Envar   string `json:"envar"`
	Help    string `json:"help"`
	Option  string `json:"option"`
}

type ContextInt

type ContextInt struct {
	Default int    `json:"default"`
	Envar   string `json:"envar"`
	Help    string `json:"help"`
	Option  string `json:"option"`
}

type ContextString

type ContextString struct {
	Default string `json:"default"`
	Envar   string `json:"envar"`
	Help    string `json:"help"`
	Option  string `json:"option"`
}

type ContextStringSlice

type ContextStringSlice struct {
	Default []string `json:"default"`
	Envar   string   `json:"envar"`
	Help    string   `json:"help"`
	Option  string   `json:"option"`
}

type ContextVariables

type ContextVariables struct {
	Bools        []ContextBool        `json:"bools"`
	Ints         []ContextInt         `json:"ints"`
	Strings      []ContextString      `json:"strings"`
	StringSlices []ContextStringSlice `json:"stringSlices"`
}

Jump to

Keyboard shortcuts

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