grouped_flags

package
v2.0.0-...-a21236f Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package grouped_flags provides a small wrapper around the flag package from Go's standard library to allow grouping flags in the help output. Please see the example for more details.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FlagGroupSet

type FlagGroupSet struct {
	// contains filtered or unexported fields
}

func NewFlagGroupSet

func NewFlagGroupSet(errorHandling flag.ErrorHandling) *FlagGroupSet
Example
os.Args = []string{"tusd", "-h"}

fs := NewFlagGroupSet(flag.ContinueOnError)
fs.SetOutput(os.Stdout)

var host string
var behindProxy bool
var maxSize int64
var timeout time.Duration

fs.AddGroup("Listening options", func(f *flag.FlagSet) {
	f.StringVar(&host, "host", "0.0.0.0", "Host to bind HTTP server to")
	f.BoolVar(&behindProxy, "behind-proxy", false, "Respect X-Forwarded-* and similar headers which may be set by proxies")
})

fs.AddGroup("Upload protocol options", func(f *flag.FlagSet) {
	f.Int64Var(&maxSize, "max-size", 0, "Maximum size of a single upload in bytes")
})

fs.AddGroup("Timeout options", func(f *flag.FlagSet) {
	f.DurationVar(&timeout, "read-timeout", 60*time.Second, "Network read timeout. If the tusd does not receive data for this duration, it will consider the connection dead. A zero value means that network reads will not time out.")
})

fs.Parse()
Output:

Usage of tusd:

Listening options:
  -behind-proxy
    	Respect X-Forwarded-* and similar headers which may be set by proxies
  -host string
    	Host to bind HTTP server to (default "0.0.0.0")

Upload protocol options:
  -max-size int
    	Maximum size of a single upload in bytes

Timeout options:
  -read-timeout duration
    	Network read timeout. If the tusd does not receive data for this duration, it will consider the connection dead. A zero value means that network reads will not time out. (default 1m0s)

func (*FlagGroupSet) AddGroup

func (f *FlagGroupSet) AddGroup(name string, constructor func(*flag.FlagSet))

func (FlagGroupSet) Parse

func (f FlagGroupSet) Parse() error

func (*FlagGroupSet) SetOutput

func (f *FlagGroupSet) SetOutput(output io.Writer)

func (*FlagGroupSet) Usage

func (f *FlagGroupSet) Usage()

Jump to

Keyboard shortcuts

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