usage

package
v0.0.0-...-c8a214a Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2018 License: Apache-2.0 Imports: 4 Imported by: 9

Documentation

Overview

Package usages provides a mechanism to insert and recover richer usage information (eg whether a flag is required, whether it contains sensitive information) into and from a flag.Flag usage string, respectively.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Deprecated

func Deprecated(usage string) string

Deprecated produces an encoded usage string for a Flag indiciating that the Flag is deprecated. It can be passed through usage.New() to recover the full Usage.

func DeprecatedAndSet

func DeprecatedAndSet(fs *flag.FlagSet) []string

DeprecatedAndSet produces a slice of the names of all flags for which the Usage string indiciates deprecation but are set

func FilterFlagSet

func FilterFlagSet(fs *flag.FlagSet, fn FlagSetFilterFn) []string

FilterFlagSet produces a slice of the names of flags for which the given FilterFn returns true

func IsDeprecated

func IsDeprecated(f *flag.Flag) bool

IsDeprecated checks the usage string of the given Flag to see if it is marked as deprecated.

func IsRequired

func IsRequired(f *flag.Flag) bool

IsRequired checks the usage string of the given Flag to see if it is marked as required.

func IsSensitive

func IsSensitive(f *flag.Flag) bool

IsSensitive checks the usage string of the given Flag to see if it is marked as sensitive.

func MissingRequired

func MissingRequired(fs *flag.FlagSet) []string

MissingRequired produces a slice of the names of all flags for which the Usage string indiciates requiredness but no value is set.

func Required

func Required(usage string) string

Required produces an encoded usage string for a Flag indiciating that the Flag is required. It can be passed through usage.New() to recover the full Usage.

func Sensitive

func Sensitive(usage string) string

Sensitive produces a usage string for a Flag indiciating that the Flag is required. It can be passed through usage.New() to recover the full Usage.

Types

type FlagSetFilterFn

type FlagSetFilterFn func(f *flag.Flag, set bool) bool

FlagSetFilterFn is a predicate function that takes a flag and whether or not the flag is set as its input.

type Usage

type Usage interface {
	// Usage returns the original usage string, without any decoration
	Usage() string

	// IsRequired returns true if the flag has been marked as required
	IsRequired() bool

	// IsSensitive returns true if the flag has been marked as containing
	// sensitive information that should't be dispayed.
	IsSensitive() bool

	// IsDeprecated returns true if the flag has been marked as deprecated
	IsDeprecated() bool

	// SetRequired marks the flag as required
	SetRequired() Usage

	// SetSensitive marks the flag as containing sensitive information that
	// should't be dispayed.
	SetSensitive() Usage

	// SetDeprecated marks the flag as deprecated
	SetDeprecated() Usage

	// Pretty() returns a human-friendly usage string, decorated with an
	// indication of whether the flag has been marked as required or sensitive
	Pretty() string

	// String() returns an encoded string that can be passed to New() to recover
	// the full state of the Usage later.
	String() string
}

Usage represents richer usage information for a flag.Flag

func New

func New(str string) Usage

New produces a new Usage from a string. The string can be either a conventual usage descrition, or a usage-encoded string.

Jump to

Keyboard shortcuts

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