Documentation
¶
Overview ¶
Example ¶
cmd := ccli.NewCommand() cmd.Name = exampleAppName cmd.Usage = exampleUsage cmd.Version = exampleVersion // cmd.Run(context.Background(), os.Args)
Index ¶
- func Apply(cmd *cli.Command)
- func ApplyWith(cmd *cli.Command, opts ...Option)
- func ApplyWithOptions(cmd *cli.Command, opts Options)
- func NewCommand() *cli.Command
- func NewCommandWith(opts ...Option) *cli.Command
- func NewCommandWithOptions(opts Options) *cli.Command
- type ColorFunc
- type Option
- type Options
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Apply ¶
Apply recursively sets colored help templates on all subcommands of cmd using default colors. Call this after adding subcommands to ensure they get colored help output.
Example ¶
cmd := ccli.NewCommand()
cmd.Name = exampleAppName
cmd.Usage = exampleUsage
cmd.Commands = []*cli.Command{
{Name: "serve", Usage: "start the server"},
}
ccli.Apply(cmd)
// cmd.Run(context.Background(), os.Args)
func ApplyWith ¶
ApplyWith recursively sets colored help templates on all subcommands of cmd using functional options. Call this after adding subcommands.
func ApplyWithOptions ¶
ApplyWithOptions recursively sets colored help templates on all subcommands of cmd using the provided color options. Call this after adding subcommands.
func NewCommand ¶
NewCommand creates a new root command with colored help output using default colors. All help templates are set per-command via CustomRootCommandHelpTemplate and CustomHelpTemplate, avoiding global side effects.
func NewCommandWith ¶
NewCommandWith creates a new root command with colored help output, configured by functional options. Unset colors fall back to defaults. All help templates are set per-command, avoiding global side effects.
Example ¶
cmd := ccli.NewCommandWith( ccli.WithGreen(color.New(color.FgHiGreen).SprintFunc()), ccli.WithYellow(color.New(color.FgHiYellow).SprintFunc()), ) cmd.Name = exampleAppName cmd.Usage = exampleUsage // cmd.Run(context.Background(), os.Args)
Example (Disable) ¶
cmd := ccli.NewCommandWith(ccli.WithDisable()) cmd.Name = exampleAppName cmd.Usage = exampleUsage // cmd.Run(context.Background(), os.Args)
func NewCommandWithOptions ¶
NewCommandWithOptions creates a new root command with colored help output using the provided color options. Any nil color function in opts falls back to the default color. Set Disable to true to turn off all coloring. All help templates are set per-command, avoiding global side effects.
Example ¶
cmd := ccli.NewCommandWithOptions(ccli.Options{
Green: color.New(color.FgHiGreen).SprintFunc(),
Yellow: color.New(color.FgHiYellow).SprintFunc(),
Blue: nil,
Cyan: nil,
Red: nil,
Disable: false,
})
cmd.Name = exampleAppName
cmd.Usage = exampleUsage
// cmd.Run(context.Background(), os.Args)
Types ¶
type Option ¶
type Option func(*Options)
Option is a functional option for configuring a ccli application.
func WithYellow ¶
WithYellow sets the color function for section headers.
type Options ¶
type Options struct {
// Blue is used for author names. Defaults to color.FgBlue.
Blue ColorFunc
// Cyan is used for usage text. Defaults to color.FgCyan.
Cyan ColorFunc
// Green is used for app/command names. Defaults to color.FgGreen.
Green ColorFunc
// Red is used for copyright text. Defaults to color.FgRed.
Red ColorFunc
// Yellow is used for section headers. Defaults to color.FgYellow.
Yellow ColorFunc
// Disable turns off all coloring. When true, all color functions
// are replaced with plain fmt.Sprint.
Disable bool
}
Options allows customizing the color scheme used in help output.
