help

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package help renders command help, usage, version, and completion instructions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Format

func Format(cmdChain []*spec.Command) string

Format returns the complete, formatted help screen for the given command chain.

func FormatWith

func FormatWith(cmdChain []*spec.Command, opts Options) string

FormatWith returns the complete, formatted help screen for the given command chain, delegating feature-specific sections to the optional renderers in opts. The completion subsystem is reachable only through renderers installed by the completion-enabled engine path.

func Hint

func Hint(cmdChain []*spec.Command) string

Hint returns the short hint pointing the user to --help.

func RenderCompletionFooter

func RenderCompletionFooter(cmdChain []*spec.Command, useFlag bool, detect func() (completion.CurrentShell, bool), width int) string

RenderCompletionFooter renders the generic completion screen footer: the supported-shells list plus the dynamically generated current-shell enable hints. It is the completion-enabled implementation behind Options.CompletionFooter; detect resolves the caller's shell and is injectable for deterministic tests, and width carries the wrap width (zero resolves through termwidth). The per-shell instructions pointer is suppressed when the completion command's help flag is disabled, since the referenced invocation would be a usage error. An empty command chain renders nothing.

func RenderCompletionInstructions

func RenderCompletionInstructions(shell string, useFlag bool, rootName string) string

RenderCompletionInstructions renders the enable instructions body of a completion screen pinned to one shell. It is the completion-enabled implementation behind Options.CompletionInstructions.

func RenderFeatures

func RenderFeatures(root *spec.Command, width int) string

RenderFeatures renders the automatic Features section of the root help screen: one aligned row per feature toggle, in declaration order, carrying the feature's help text followed by its declared stage, integer levels, default, and bound environment variables. GA and deprecated features are omitted — they are no longer experimental — and the section renders nothing when no feature remains. Width carries the wrap width (zero resolves through termwidth). It is the feature-enabled implementation behind Options.FeaturesSection.

func Usage

func Usage(cmdChain []*spec.Command) string

Usage returns the standard 1-2 line usage syntax for the given command chain.

func VersionDetailed

func VersionDetailed(appName string, userVersion string) string

VersionDetailed formats the docker-style multi-line version block (for the `version` subcommand), with the full commit hash and commit timestamp.

func VersionJSON

func VersionJSON(userVersion string) string

VersionJSON formats the flat machine-readable version object (for `version --json`). Every key is always present; unknown values are empty strings.

func VersionSummary

func VersionSummary(appName string, userVersion string) string

VersionSummary formats the single-line version string (for --version): "<app> has version <version> built with <go>" plus " from <commit>" and " on <commit time>" when the version string does not already embed them.

Types

type BuildInfoData

type BuildInfoData struct {
	Version    string
	Commit     string
	CommitDate string
	Dirty      bool
	GoVersion  string
	OS         string
	Arch       string
}

BuildInfoData holds build-time metadata extracted from Go runtime and debug information.

func GetBuildInfo

func GetBuildInfo(userVersion string) BuildInfoData

GetBuildInfo extracts build metadata from runtime/debug.ReadBuildInfo().

type Options

type Options struct {
	// Width is the column width help text wraps at. Zero resolves through
	// termwidth: a COLUMNS override when set, else the default width.
	Width int
	// CompletionInstructions renders the per-shell enable instructions of a
	// completion command pinned to one shell (e.g. `--completion zsh --help`).
	CompletionInstructions func(shell string, useFlag bool, rootName string) string
	// CompletionFooter renders the supported-shells footer of the generic
	// completion screen.
	CompletionFooter func(cmdChain []*spec.Command, useFlag bool, width int) string
	// FeaturesSection renders the automatic Features section of the root help
	// screen. It is reached exclusively through the feature-enabled engine
	// path, so applications that never enable features keep the feature help
	// payload unreferenced.
	FeaturesSection func(root *spec.Command, width int) string
}

Options carries optional feature renderers for feature-specific help screens. The zero value renders every screen without completion-specific sections: the completion subsystem is reachable only through renderers installed by the completion-enabled engine path.

Jump to

Keyboard shortcuts

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