flag

package
v0.0.0-...-c18a219 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2023 License: MIT Imports: 6 Imported by: 5

Documentation

Overview

Package flag implements command-line flag parsing. It's a wrapper of flag pkg in stdlib.

Index

Constants

View Source
const (
	ContinueOnError = flag.ContinueOnError // Return a descriptive error.
	ExitOnError     = flag.ExitOnError     // Call os.Exit(2).
	PanicOnError    = flag.PanicOnError    // Call panic with a descriptive error.
)

Variables

View Source
var Default = Wrap(flag.CommandLine, "")

Functions

func Bool

func Bool(full, short string, value bool, usage string) *bool

func BoolVar

func BoolVar(p *bool, full, short string, value bool, usage string)

func Duration

func Duration(full, short string, value time.Duration, usage string) *time.Duration

func DurationVar

func DurationVar(p *time.Duration, full, short string, value time.Duration, usage string)

func Float64

func Float64(full, short string, value float64, usage string) *float64

func Float64Var

func Float64Var(p *float64, full, short string, value float64, usage string)

func Int

func Int(full, short string, value int, usage string) *int

func Int64

func Int64(full, short string, value int64, usage string) *int64

func Int64Var

func Int64Var(p *int64, full, short string, value int64, usage string)

func IntVar

func IntVar(p *int, full, short string, value int, usage string)

func Parse

func Parse()

func Register

func Register(f CommonFlag)

Register adds common flags like help/version/profile/config etc.

func String

func String(full, short, value, usage string) *string

func StringVar

func StringVar(p *string, full, short, value, usage string)

func Uint

func Uint(full, short string, value uint, usage string) *uint

func Uint64

func Uint64(full, short string, value uint64, usage string) *uint64

func Uint64Var

func Uint64Var(p *uint64, full, short string, value uint64, usage string)

func UintVar

func UintVar(p *uint, full, short string, value uint, usage string)

func Usage

func Usage()

func Var

func Var(v flag.Value, full, short string, usage string)

Types

type CommonFlag

type CommonFlag int

CommonFlag represents pre-defined flags.

const (
	Help CommonFlag = 1 << iota
	Version
	Profile
	Config
	All = Help | Version | Profile | Config
)

Pre-defined common flags

type ErrorHandling

type ErrorHandling = flag.ErrorHandling

type Flag

type Flag struct {
	FullName  string
	ShortName string
	Default   interface{}
	Usage     string
}

type Set

type Set struct {
	Desc string
	// contains filtered or unexported fields
}

func NewSet

func NewSet(name, desc string, errorHandling ErrorHandling) *Set

func Wrap

func Wrap(fs *flag.FlagSet, desc string) *Set

func (*Set) Args

func (s *Set) Args() []string

Args returns the non-flag arguments.

func (*Set) Bool

func (s *Set) Bool(full, short string, value bool, usage string) *bool

func (*Set) BoolVar

func (s *Set) BoolVar(p *bool, full, short string, value bool, usage string)

func (*Set) Duration

func (s *Set) Duration(full, short string, value time.Duration, usage string) *time.Duration

func (*Set) DurationVar

func (s *Set) DurationVar(p *time.Duration, full, short string, value time.Duration, usage string)

func (*Set) Float64

func (s *Set) Float64(full, short string, value float64, usage string) *float64

func (*Set) Float64Var

func (s *Set) Float64Var(p *float64, full, short string, value float64, usage string)

func (*Set) Inner

func (s *Set) Inner() *flag.FlagSet

Inner returns internal `flag.FlagSet` used by Set.

func (*Set) Int

func (s *Set) Int(full, short string, value int, usage string) *int

func (*Set) Int64

func (s *Set) Int64(full, short string, value int64, usage string) *int64

func (*Set) Int64Var

func (s *Set) Int64Var(p *int64, full, short string, value int64, usage string)

func (*Set) IntVar

func (s *Set) IntVar(p *int, full, short string, value int, usage string)

func (*Set) Lookup

func (s *Set) Lookup(name string) *flag.Flag

func (*Set) Parse

func (s *Set) Parse(args []string)

func (*Set) Register

func (s *Set) Register(f CommonFlag)

Register adds common flags like help/version/profile/config etc.

func (*Set) Set

func (s *Set) Set(name, value string) error

func (*Set) SetUsageStyle

func (s *Set) SetUsageStyle(style UsageStyle)

func (*Set) String

func (s *Set) String(full, short, value, usage string) *string

func (*Set) StringVar

func (s *Set) StringVar(p *string, full, short, value, usage string)

func (*Set) Uint

func (s *Set) Uint(full, short string, value uint, usage string) *uint

func (*Set) Uint64

func (s *Set) Uint64(full, short string, value uint64, usage string) *uint64

func (*Set) Uint64Var

func (s *Set) Uint64Var(p *uint64, full, short string, value uint64, usage string)

func (*Set) UintVar

func (s *Set) UintVar(p *uint, full, short string, value uint, usage string)

func (*Set) Usage

func (s *Set) Usage()

func (*Set) Var

func (s *Set) Var(v flag.Value, full, short string, usage string)

type StringList

type StringList []string

func (*StringList) Set

func (l *StringList) Set(value string) error

func (*StringList) String

func (l *StringList) String() string

type UsageStyle

type UsageStyle int32

UsageStyle defines the usage style.

const (
	// Compact is left-right style
	Compact UsageStyle = iota
	// Manual is up-down style
	Manual
)

func (UsageStyle) Print

func (s UsageStyle) Print(w io.Writer, title, desc string)

Jump to

Keyboard shortcuts

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