cmdhelper

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: Apache-2.0 Imports: 8 Imported by: 14

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Init

func Init(cobraCommand *cobra.Command, contextVariables []option.ContextVariable)

Performs cobra.Flags.<datatype> operations on a list of contextVariables.

Example
cobraCommand := &cobra.Command{
	Use:   "example-use",
	Short: "example-short",
	Long:  `example-long`,
}
var contextVariables = []option.ContextVariable{
	{
		Default: "",
		Envar:   "MY_VARIABLE",
		Help:    "Description of my variable [%s]",
		Arg:     "my-variable",
		Type:    optiontype.String,
	},
}
Init(cobraCommand, contextVariables)
Output:

func PreRun

func PreRun(cobraCommand *cobra.Command, args []string, configName string, contextVariables []option.ContextVariable)

A function that can be wrapped for use by cobra.Command.PreRun.

Example
cobraCommand := &cobra.Command{
	Use:   "example-use",
	Short: "example-short",
	Long:  `example-long`,
}
var contextVariables = []option.ContextVariable{
	{
		Default: "",
		Envar:   "MY_VARIABLE",
		Help:    "Description of my variable [%s]",
		Arg:     "my-variable",
		Type:    optiontype.String,
	},
}
Init(cobraCommand, contextVariables)
PreRun(cobraCommand, []string{}, "example-cmd", contextVariables)
Output:

func SetCobraFlag

func SetCobraFlag(cobraCommand *cobra.Command, contextVariable option.ContextVariable)

Performs cobra.Flag.<datatype> on a option.ContextVariable.

func Version

func Version(version string, iteration string) string

Return a formatted version string.

Example
result := Version("1.2.3", "4")
fmt.Println(result)
Output:

1.2.3-4

Types

This section is empty.

Jump to

Keyboard shortcuts

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