pcli

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2016 License: Apache-2.0 Imports: 10 Imported by: 30

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BoolFlagToCli

func BoolFlagToCli(s Flag) interface{}

func BoolTFlagToCli

func BoolTFlagToCli(s Flag) interface{}

func IntFlagToCli

func IntFlagToCli(s Flag) interface{}

func StringFlagToCli

func StringFlagToCli(s Flag) interface{}

func StringSliceFlagToCli

func StringSliceFlagToCli(s Flag) interface{}

func UnmarshalFlags added in v0.0.7

func UnmarshalFlags(obj interface{}, c *cli.Context) error

UnmarshalFlags populates obj from the specified CLI context. By default, it will populate a struct field named "FooBar" with the contents of the flag "foo-bar". You can override this behavior and specify the flag name with the `omg:"flag-name"` struct tag.

Warning - UnmarshalFlags may zero-out any fields that were not specified in the context. If you want UnmarshalFlags to leave a field alone under all circumstances, then annotate it with the `omg:"-"` tag.

By default, UnmarshalFlags assumes that all fields in obj that are not explicitly skipped over with `omg:"-"` are required flags. It will return an error if a required flag is missing.

If a flag is not required and you don't want an error if it's missing, the flag can be annotated with `omg:"flag-name,optional"`. Note that the flag name is required in addition to 'optional' in this case.

Types

type Flag

type Flag struct {
	Name     string
	Usage    string
	EnvVar   string
	Value    string
	FlagType FlagType
}

func CreateBoolFlag added in v0.0.7

func CreateBoolFlag(name, usage string) Flag

CreateBoolFlag creates a bool flag that is false by default.

func CreateBoolTFlag added in v0.0.7

func CreateBoolTFlag(name, usage string) Flag

CreateBoolTFlag creates a bool flag that is true by default.

func CreateIntFlag added in v0.0.7

func CreateIntFlag(name, usage string, value ...string) Flag

CreateIntFlag creates an int flag with an optional default value.

func CreateStringFlag added in v0.0.7

func CreateStringFlag(name, usage string, value ...string) Flag

CreateStringFlag creates a string flag with an optional default value.

func CreateStringSliceFlag added in v0.0.7

func CreateStringSliceFlag(name, usage string, value ...string) Flag

CreateStringSliceFlag creates a string slice flag with an optional default value.

func (Flag) ToCli

func (s Flag) ToCli() interface{}

type FlagType

type FlagType int
const (
	StringFlag FlagType = iota
	StringSliceFlag
	BoolFlag
	IntFlag
	BoolTFlag
)

Jump to

Keyboard shortcuts

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