Documentation
¶
Overview ¶
Package urfavehelp provides a clean, terminal-aware help formatter for github.com/urfave/cli/v3.
Features:
- Aligned columns: arguments, commands, and flags share a single vertical gutter.
- Smart word wrapping: reflows descriptions at terminal width with hanging indents.
- Clean placeholders: enforces <value> on value flags without repeating flag names.
- Positional arguments: document arguments with SetArgs or native cli.Command.Arguments.
- Sanitized defaults: hides dynamic machine-local paths like os.Executable.
- Subcommand aliases: displays command aliases (e.g. list, ls) with aligned spacing.
Quick Start ¶
Enable urfavehelp with a single line:
package main
import (
"context"
"os"
"github.com/urfave/cli/v3"
urfavehelp "github.com/zigai/urfave-help"
)
func main() {
cmd := &cli.Command{
Name: "mytool",
Usage: "A production command-line interface",
}
urfavehelp.Install()
_ = cmd.Run(context.Background(), os.Args)
}
Index ¶
- Constants
- Variables
- func Install(opts ...Option)
- func NewPrinter(opts ...Option) cli.HelpPrinterFunc
- func PrintHelp(w io.Writer, cmd *cli.Command, opts Options)
- func SetArgs(cmd *cli.Command, args ...Arg)
- func TerminalWidth(w any) int
- func WithArgs(args ...Arg) func(*cli.Command)
- type Arg
- type Option
- type Options
Constants ¶
const DefaultArgsMetadataKey = "urfave_help_arguments"
DefaultArgsMetadataKey stores positional argument documentation in Command.Metadata.
const LegacyArgsMetadataKey = "aht_help_arguments"
LegacyArgsMetadataKey is a fallback key for backward compatibility.
Variables ¶
var HelpPrinter = NewPrinter()
HelpPrinter is the default HelpPrinterFunc.
Functions ¶
func Install ¶
func Install(opts ...Option)
Install registers the custom help formatter with urfave/cli.
func NewPrinter ¶
func NewPrinter(opts ...Option) cli.HelpPrinterFunc
NewPrinter creates a cli.HelpPrinterFunc configured with the given options.
func TerminalWidth ¶
TerminalWidth returns the terminal column count, or 0 if w is not an os.File terminal.
Types ¶
type Option ¶
type Option func(*Options)
Option configures help printer options.
func WithGutterGap ¶
WithGutterGap sets the spacing between labels and descriptions.
func WithMetavarResolver ¶
WithMetavarResolver sets a custom resolver for flag placeholder names.
func WithMinDescWidth ¶
WithMinDescWidth sets the minimum readable width allocated to wrapped descriptions.
func WithPathPrefixFilter ¶
WithPathPrefixFilter sets the prefix used to suppress dynamic path leaks in defaults (e.g. "/").
func WithWidths ¶
WithWidths sets the minimum, maximum, and non-TTY fallback widths for word wrapping.
type Options ¶
type Options struct {
// MinWidth is the lower bound for terminal word wrapping (default: 60).
MinWidth int
// MaxWidth is the upper bound for terminal word wrapping (default: 0, uncapped).
MaxWidth int
// DefaultWidth is the fallback width when stdout is not a terminal (default: 100).
DefaultWidth int
// IndentSpaces is the section indentation (default: 2).
IndentSpaces int
// GutterGap is the spacing between labels and descriptions (default: 2).
GutterGap int
// MinDescWidth is the minimum width allocated for wrapped descriptions (default: 20).
MinDescWidth int
// PathPrefixFilter suppresses flag defaults starting with this prefix (default: "/").
PathPrefixFilter string
// CustomMetavar overrides flag placeholder resolution.
CustomMetavar func(cli.Flag) string
}
Options configures help layout, word wrapping, and formatting.
func DefaultOptions ¶
func DefaultOptions() Options
DefaultOptions returns the default formatting configuration.