konghelp

package module
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2025 License: MIT Imports: 11 Imported by: 1

README

kong-help

Library to generate pretty help output for Go CLI's that use alecthomas/kong. Help output based heavily on the format used by rendercv.

Basic Example

package main

import (
	"github.com/alecthomas/kong"
	konghelp "github.com/ohhfishal/kong-help"
	"os"
)

type CMD struct {
    // ...
}

func main() {
	var cli CMD
	kongCtx := kong.Parse(
		&cli,
        /* Just add this new option to kong.Parse */
		konghelp.Help(),
	)

	if err := kongCtx.Run(); err != nil {
		fmt.Fprintln(os.Stderr, err.Error())
		os.Exit(1)
	}
}

A more detail example can be found in _examples/readme/main.go.

Upcoming

  • Better examples/docs
  • Support for command grouping
  • Support for all kong.HelpOption's
  • Help formatting options? (IE control of styling)
  • Tests

Documentation

Index

Constants

View Source
const DefaultWidth = 80

DefaultWidth is the fallback width if it can not be automatically determined.

Variables

View Source
var ColorCommand = color.New(color.FgCyan).SprintFunc()
View Source
var ColorDefault = color.New(color.FgMagenta).SprintFunc()
View Source
var ColorExample = color.New(color.FgYellow).SprintFunc()

TODO: Make these configurable

View Source
var ColorGroup = color.New(color.FgBlue).Add(color.Underline).SprintFunc()
View Source
var ColorPlaceHolder = ColorDefault
View Source
var ColorRequired = color.New(color.FgRed).SprintFunc()
View Source
var ColorType = ColorExample

Functions

func AggregateIntoLines

func AggregateIntoLines(parts []string, maxWidth int) ([]string, error)

func Help

func Help(options ...Options) kong.Option

func NewPrettyPrinter added in v0.2.0

func NewPrettyPrinter(printOpts Options) kong.HelpPrinter

func PrettyValueFormatter

func PrettyValueFormatter(formatter kong.HelpValueFormatter) kong.HelpValueFormatter

func TruncateWithSuffix added in v0.2.0

func TruncateWithSuffix(line string, width int, suffix string) string

func Visible added in v0.2.0

func Visible(str string) string

func VisibleLen

func VisibleLen(str string) int

Calculates the length of a string only counting visible characters

Types

type Options

type Options struct {
	// UseWidth controls the max width printed.
	// If UseWidth is 0, stdout's width is used instead if a terminal, otherwise 80.
	UseWidth int
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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