helpcolours

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 29, 2026 License: MIT Imports: 8 Imported by: 0

README

kong-help-colours

CI Go Reference

Drop-in colourised --help output for CLIs built with alecthomas/kong. Three colours, no configuration, just clap-style help.

Install

go get github.com/gavincarr/kong-help-colours

Use

import (
    "github.com/alecthomas/kong"
    helpcolours "github.com/gavincarr/kong-help-colours"
)

func main() {
    var cli struct {
        Verbose bool   `short:"v" help:"Enable verbose output."`
        Out     string `short:"o" placeholder:"FILE" help:"Output file."`
    }
    ctx := kong.Parse(&cli,
        kong.Help(helpcolours.Help),
        kong.ShortHelp(helpcolours.ShortHelp), // optional
    )
    _ = ctx
}

Colour scheme

Element Colour
Section headers (Usage:, Flags:, Arguments:, Commands:, group titles) yellow
Program name in the usage line; flag tokens (--foo, -f) green
Placeholders (<FILE>, [OPTIONS], =STRING) cyan

The scheme is fixed — no options, no configuration. It mirrors clap's defaults so it'll look like every Rust CLI you've used.

When colours are emitted

Colour is enabled when all of:

  • NO_COLOR env var is not set (no-color.org)
  • Either FORCE_COLOR is set, or stdout is a terminal

When colour is disabled the package delegates straight through to kong.DefaultHelpPrinter — zero overhead, byte-for-byte identical output.

Try it

go run ./cmd/demo --help

Author

Gavin Carr gavin@openfusion.net

License

MIT — see LICENSE.

Documentation

Overview

Package helpcolours adds clap-style colourised --help output to CLIs built with github.com/alecthomas/kong. Wire it in with:

kong.Parse(&cli,
    kong.Help(helpcolours.Help),
    kong.ShortHelp(helpcolours.ShortHelp), // optional
)

Colour is enabled when stdout is a terminal (or FORCE_COLOR is set) and NO_COLOR is unset.

Index

Constants

This section is empty.

Variables

View Source
var Help kong.HelpPrinter = func(options kong.HelpOptions, ctx *kong.Context) error {
	return printWithColour(options, ctx, kong.DefaultHelpPrinter)
}

Help is a kong.HelpPrinter that delegates to kong.DefaultHelpPrinter and post-processes the output to inject ANSI colour codes when colour is enabled for ctx.Stdout.

View Source
var ShortHelp kong.HelpPrinter = func(options kong.HelpOptions, ctx *kong.Context) error {
	return printWithColour(options, ctx, kong.DefaultShortHelpPrinter)
}

ShortHelp is the equivalent wrapper around kong.DefaultShortHelpPrinter, for use with kong.ShortHelp(...). Kong invokes the short-help printer when a parse error occurs, to print a one-line usage summary plus a "Run 'foo --help' for more information." pointer.

Functions

This section is empty.

Types

This section is empty.

Directories

Path Synopsis
cmd
demo command
Command demo is a small kong-based CLI used to eyeball kong-help-colours output.
Command demo is a small kong-based CLI used to eyeball kong-help-colours output.

Jump to

Keyboard shortcuts

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