synopsis

package
v0.22.0 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2026 License: BSD-3-Clause Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	OnlyShortNoValue         = OptionGroup(iota) // -v
	OnlyShortNoValueOptional                     // [-v]
	OtherOptional                                // [--long=value]
	Other                                        // --long=value
	ActionGroup                                  // { --help|--version}
	Hidden
)
View Source
const (
	Bold      = ansiterm.Bold
	Underline = ansiterm.Underline
)
View Source
const (
	ColorData    = "_synopsisColor"
	StyleData    = "_synopsisStyle"
	CategoryData = "_synopsisCategory"
)

Variables

This section is empty.

Functions

func ArgCounter

func ArgCounter(narg any) (optional, multi bool)

func CategoryFromData added in v0.19.0

func CategoryFromData(data map[string]any) string

CategoryFromData obtains the synopsis category which was set within the data of a flag, which is the empty string if the flag has no synopsis category.

func Choices added in v0.21.0

func Choices(opts []string) string

func Placeholder

func Placeholder(v any) string

Types

type Arg

type Arg struct {
	Value    string
	Multi    bool
	Optional bool
}

func NewArg

func NewArg(usage string, narg any) *Arg

func (*Arg) WithUsage

func (a *Arg) WithUsage(text string) *Arg

func (*Arg) WriteTo

func (a *Arg) WriteTo(sb styleWriter)

type Command

type Command struct {
	Name         string
	Flags        map[OptionGroup][]*Flag
	Args         []*Arg
	RequiredArgs []*Arg
	OptionalArgs []*Arg
	RTL          bool
	Style        Style

	// CondenseCategories causes flags with a SynopsisCategory set to be condensed
	// into groups
	CondenseCategories bool
}

func NewCommand

func NewCommand(name string, flags []*Flag, args []*Arg, rtl bool) *Command

func (*Command) WriteTo

func (c *Command) WriteTo(sb styleWriter)

type Expr

type Expr struct {
	Long         string
	Short        string
	Usage        *Usage
	Names        []string
	Args         []*Arg
	RequiredArgs []*Arg
	OptionalArgs []*Arg
	Style        Style
}

func NewExpr

func NewExpr(primary string, aliases []string, usage *Usage, args []*Arg) *Expr

func (*Expr) WriteTo

func (e *Expr) WriteTo(sb styleWriter)

type Flag

type Flag struct {
	Short          string
	Shorts         []rune
	Long           string
	Primary        string // Long if present, otherwise Short
	Separator      string
	Names          []string
	AlternateNames []string
	Value          *Value
	Group          OptionGroup
	Style          Style

	// Category names the synopsis category that the flag belongs to, which is
	// empty for most flags.  See Command.CondenseCategories.
	Category string

	OptionalValue bool
}

func NewFlag

func NewFlag(primary string, aliases []string, helpText, usageString string, v any, group OptionGroup) *Flag

func (*Flag) WithNo

func (f *Flag) WithNo()

func (*Flag) WithOptionalValue added in v0.21.0

func (f *Flag) WithOptionalValue(text string)

func (*Flag) WriteTo

func (f *Flag) WriteTo(sb styleWriter)

type OptionGroup

type OptionGroup int

type Stringer

type Stringer interface {
	WriteTo(styleWriter)
}

type Style added in v0.17.0

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

Style controls how the name of a flag, command, or expression is rendered in the synopsis. The zero value renders the name in Bold. When a color is set, it is used in place of the default Bold style unless a style is also set explicitly, in which case both are applied.

func StyleFromData added in v0.17.0

func StyleFromData(data map[string]any) Style

func (Style) ApplyTo added in v0.17.0

func (s Style) ApplyTo(str string) string

type Usage

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

func ParseUsage

func ParseUsage(text string) *Usage

func (*Usage) HelpText

func (u *Usage) HelpText(w styleWriter)

func (*Usage) Placeholders

func (u *Usage) Placeholders() []string

func (*Usage) WithoutPlaceholders

func (u *Usage) WithoutPlaceholders() string

type Value

type Value struct {
	Placeholder string

	Usage *Usage
	// contains filtered or unexported fields
}

func (*Value) WriteTo

func (v *Value) WriteTo(w styleWriter)

Jump to

Keyboard shortcuts

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