templates

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2024 License: MPL-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// SectionVars is the help template section that declares variables to be used in the template.
	SectionVars = `{{$isRootCmd := isRootCmd .}}` +
		`{{$rootCmd := rootCmd .}}` +
		`{{$visibleFlags := visibleFlags (flagsNotIntersected .LocalFlags .PersistentFlags)}}` +
		`{{$explicitlyExposedFlags := exposed .}}` +
		`{{$optionsCmdFor := optionsCmdFor .}}` +
		`{{$usageLine := usageLine .}}`

	// SectionAliases is the help template section that displays command aliases.
	SectionAliases = `{{if gt .Aliases 0}}Aliases:
{{.NameAndAliases}}

{{end}}`

	// SectionExamples is the help template section that displays command examples.
	SectionExamples = `{{if .HasExample}}Examples:
{{trimRight .Example}}

{{end}}`

	// SectionSubcommands is the help template section that displays the command's subcommands.
	SectionSubcommands = `{{if .HasAvailableSubCommands}}{{cmdGroupsString .}}

{{end}}`

	// SectionFlags is the help template section that displays the command's flags.
	SectionFlags = `` /* 289-byte string literal not displayed */

	// SectionPersistentFlags is the help template section that displays the command's persistent flags.
	SectionPersistentFlags = `` /* 145-byte string literal not displayed */

	// SectionUsage is the help template section that displays the command's usage.
	SectionUsage = `{{if and .Runnable (ne .UseLine "") (ne .UseLine $rootCmd)}}Usage:
  {{$usageLine}}

{{end}}`

	// SectionTipsHelp is the help template section that displays the '--help' hint.
	SectionTipsHelp = `{{if .HasSubCommands}}Use "{{$rootCmd}} <command> --help" for more information about a given command.
{{end}}`

	// SectionTipsGlobalOptions is the help template section that displays the 'options' hint for displaying global flags.
	SectionTipsGlobalOptions = `{{if $optionsCmdFor}}Use "{{$optionsCmdFor}}" for a list of global command-line options (applies to all commands).
{{end}}`
)

Variables

View Source
var DefaultWrapLimit uint = 120

Functions

func MainHelpTemplate

func MainHelpTemplate() string

MainHelpTemplate if the template for 'help' used by most commands.

func MainUsageTemplate

func MainUsageTemplate() string

MainUsageTemplate if the template for 'usage' used by most commands.

func OptionsHelpTemplate

func OptionsHelpTemplate() string

OptionsHelpTemplate if the template for 'help' used by the 'options' command.

func OptionsUsageTemplate

func OptionsUsageTemplate() string

OptionsUsageTemplate if the template for 'usage' used by the 'options' command.

func SplitFlagSet added in v1.1.0

func SplitFlagSet(g FlagGroups, f *pflag.FlagSet) []*pflag.FlagSet

func UseOptionsTemplates

func UseOptionsTemplates(cmd *cobra.Command)

Types

type CommandGroup

type CommandGroup struct {
	Message  string
	Commands []*cobra.Command
}

type CommandGroups

type CommandGroups []CommandGroup

func AddAdditionalCommands

func AddAdditionalCommands(g CommandGroups, message string, cmds []*cobra.Command) CommandGroups

func (CommandGroups) Add

func (g CommandGroups) Add(c *cobra.Command)

func (CommandGroups) Has

func (g CommandGroups) Has(c *cobra.Command) bool

type FlagExposer

type FlagExposer interface {
	ExposeFlags(cmd *cobra.Command, flags ...string) FlagExposer
}

func ActsAsRootCommand

func ActsAsRootCommand(cmd *cobra.Command, filters []string, cg CommandGroups, fg FlagGroups, envPrefix string) FlagExposer

type FlagGroup

type FlagGroup struct {
	Name   string
	Prefix []string
}

type FlagGroups

type FlagGroups []FlagGroup

type HelpFlagPrinter

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

HelpFlagPrinter is a printer that processes the help flag and print it to i/o writer

func NewHelpFlagPrinter

func NewHelpFlagPrinter(out io.Writer, envPrefix string, wrapLimit uint) *HelpFlagPrinter

NewHelpFlagPrinter will initialize a HelpFlagPrinter given the i/o writer

func (*HelpFlagPrinter) PrintHelpFlag

func (p *HelpFlagPrinter) PrintHelpFlag(flag *flag.Flag)

PrintHelpFlag will beautify the help flags and print it out to p.out

type MarkdownFlagPrinter added in v1.1.0

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

func NewMarkdownFlagPrinter added in v1.1.0

func NewMarkdownFlagPrinter(out io.Writer, envPrefix string) *MarkdownFlagPrinter

func (*MarkdownFlagPrinter) PrintHelpFlag added in v1.1.0

func (p *MarkdownFlagPrinter) PrintHelpFlag(f *pflag.Flag)

type YamlFlagPrinter added in v1.1.0

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

func NewYamlFlagPrinter added in v1.1.0

func NewYamlFlagPrinter(out io.Writer, wrapLimit uint) *YamlFlagPrinter

func (*YamlFlagPrinter) PrintHelpFlag added in v1.1.0

func (p *YamlFlagPrinter) PrintHelpFlag(f *pflag.Flag)

Jump to

Keyboard shortcuts

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