Documentation ¶
Overview ¶
Package ffhelp provides tools to produce help text for flags and commands.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var DefaultColumns = 120
DefaultColumns is the default value returned by Columns.
var DefaultLinePrefix = " "
DefaultLinePrefix is used by Section constructors in this package.
Functions ¶
func Columns ¶
func Columns() int
Columns in the current TTY, or DefaultColumns if the TTY can't be determined.
func FormatFlag ¶
FormatFlag is a simple helper to format a flag in a single motion.
Types ¶
type Flag ¶
type Flag struct{ ff.Flag }
Flag wraps ff.Flag to implement fmt.Formatter. It's relatively low-level. Most consumers are probably better served by higher-level helpers.
func WrapFlag ¶
func WrapFlag(f ff.Flag) Flag
WrapFlag lets you write ffhelp.WrapFlag(f) instead of ffhelp.Flag{Flag: f}.
func (Flag) Format ¶
Format implements fmt.Formatter with support for the following verbs.
VERB DESCRIPTION EXAMPLE %s short and long name, comma delimited "f, foo" %+s like %s with hyphen prefixes "-f, --foo" %#+s like %+s with empty short names padded " --foo" %v like %s with placeholder suffix "f, foo STR" %+v like %+s with placeholder suffix "-f, --foo STR" %#+v like %#+s with placeholder suffix " --foo STR" %n short name "f" %+n short name with one-hyphen prefix "-f" %l long name "foo" %+l long name with two-hyphen prefix "--foo" %u usage text "foo parameter" %k placeholder "STR" %d default value "bar"
See the tests for more complete examples.
type FlagSpec ¶
type FlagSpec struct { Flag ff.Flag Spec string // "-f, --foo STRING" Usage string // "value of foo parameter (default: bar)" }
FlagSpec represents a single-line help text for an ff.Flag. That line consists of two parts: the spec, which is a fixed-width formatted description of the flag names and placeholder; and the usage, which is a combination of the usage string and the default value (if non-empty).
func MakeFlagSpec ¶
func MakeFlagSpec(f ff.Flag) FlagSpec
func (FlagSpec) String ¶
String returns a tab-delimited and newline-terminated string containing the spec and the usage. It's intended to be written to a tabwriter.Writer.
type Help ¶
type Help []Section
Help represents help output for a flag set, command, etc.
func Command ¶
func Command(cmd *ff.Command) Help
Command returns a standard Help for the given command.
This function is meant as reasonable default for most users, and as an example. Callers who want different help output should implement their own Help value constructors like this one.
func Flags ¶
Flags returns a default Help value representing fs. If usage strings are provided, they're used as lines in a USAGE section, included before any FLAGS sections.
This function is meant as reasonable default for most users, and as an example. Callers who want different help output should implement their own Help value constructors like this one.
type Section ¶
type Section struct { // Title of the section, typically UPPERCASE. Title string // Lines in the section. Lines should be formatted for the user device, i.e. // long lines should be split into multiple lines. Each line is prefixed // with LinePrefix before being rendered. Lines []string // LinePrefix is prefixed to each line when the section is rendered. LinePrefix string // LineColumns indicates that each line is a tab-delimited set of fields, // and therefore will be rendered in a columnar format via text/tabwriter. LineColumns bool }
Section describes a single block of help text. A section usually begins with an uppercase TITLE, and contains one or more lines of content, which are typically indented by LinePrefix.
func NewFlagsSection ¶
func NewFlagsSection(fs ff.Flags) Section
NewFlagsSection returns a single FLAGS section representing every flag available to fs. Each flag is rendered via FlagSpec.
func NewFlagsSections ¶
func NewFlagsSections(fs ff.Flags) []Section
NewFlagsSections returns FLAGS section(s) representing every flag available to fs. Flags are grouped into sections according to their parent flag set. Each flag is rendered via FlagSpec.
func NewSection ¶
NewSection returns a section with the given title and lines, using DefaultLinePrefix.
func NewSubcommandsSection ¶
func NewSubcommandsSection(subcommands []*ff.Command) Section
NewSubcommandsSection returns a SUBCOMMANDS section containing one line for every subcommand in the slice. Lines consist of the subcommand name and the ShortHelp for that subcommand, in a columnar format.
func NewUntitledSection ¶
NewUntitledSection returns a section with no title and the given lines, with no line prefix.