cli

package
v0.0.0-...-b73ccf1 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrFlagBinding = errors.New("failed to bind flag")

Functions

func InitFlags

func InitFlags(v *viper.Viper, flags *pflag.FlagSet, bindings []FlagBinding) error

InitFlags sets up the accepted flags in a command line program and then bind the values set in the flags by the user to the target variable or field in a struct object.

func NewViper

func NewViper(envPrefix string) *viper.Viper

Types

type FlagBinding

type FlagBinding struct {
	Usage     string
	Name      string
	Shorthand rune // One character for a shorthand.
	Target    any
	Default   any
	Parser    FlagBindingParser
}

FlagBinding represents the info for simplify the setup of the popular command line management packages such as spf13/pflag and spf13/viper.

  1. Set up the name (posix flag aka pflag), shorthand (arg), and usage (description) of a flag.
  2. Define the default value of a flag.
  3. Once a flag is set by the user, where to bind the value of a flag to a target (variable or a field in a struct object).

type FlagBindingParser

type FlagBindingParser func(v *viper.Viper, flags *pflag.FlagSet, binding *FlagBinding) error

Jump to

Keyboard shortcuts

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