clitree

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: Apache-2.0 Imports: 6 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package clitree is hopsesh's visible command tree as `--help` shows it, and the checks that hold the skill to it: every command and flag the skill names exists, and every visible flag is in the skill or allowed to be missing from it. The CLI's tests build the tree from the cobra commands; internal/devtools/skillcheck builds it from a built program's help, so a release is checked as shipped. Both print the same golden.

Index

Constants

This section is empty.

Variables

View Source
var Skip = map[string]bool{"help": true, "completion": true}

Skip are commands left out of the tree everywhere: cobra's own.

Functions

func CheckDocumented

func CheckDocumented(t Tree, files map[string][]byte, allowed Allowed) []string

CheckDocumented returns every visible flag of every command that the skill does not mention and the allowlist does not excuse, and every allowlist entry that is stale: its flag is gone, or the skill mentions it now.

func CheckSkill

func CheckSkill(t Tree, root string, files map[string][]byte) []string

CheckSkill returns what in the skill files (rendered with the program named root) does not exist in the tree: a command an invocation names (`hopsesh clouds cleanup --list`, or a bare `hosts allow`), a flag on the command it is given to, or a flag in a "## <commands> flags" table that one of those commands lacks.

func Diff

func Diff(want, got string) string

Diff lists the lines of a golden only one side has: "- " the want's, "+ " the got's. Flags repeat under several commands, so it points at a change rather than placing it.

func Documented

func Documented(files map[string][]byte) map[string]bool

Documented is every --flag the skill files name anywhere.

func Undocumented

func Undocumented(t Tree, files map[string][]byte) []string

Undocumented lists the entries an allowlist needs now, for a first one.

Types

type Allowed

type Allowed map[string]string // "hopsesh hosts setup --json" → why

Allowed is the allowlist of visible flags the skill need not mention: lines of "<command path> --flag # why", blank lines and #-comments ignored.

func ParseAllowed

func ParseAllowed(text string) (Allowed, []string)

ParseAllowed reads an allowlist, refusing entries without a reason and duplicates.

type Command

type Command struct {
	Path     string   // "hopsesh clouds cleanup"
	Children []string // visible subcommands' names
	Flags    []Flag   // its own (help's "Flags:"), help excluded
	Global   []Flag   // inherited (help's "Global Flags:")
}

Command is one visible command.

func (Command) Has

func (c Command) Has(name string) bool

Has reports whether the command takes --name, its own or inherited.

type Flag

type Flag struct {
	Name  string // "to"
	Short string // "y", or ""
	Arg   string // the value's name ("string", "dir"), "" for a switch
}

Flag is one flag as help prints it: "-y, --yes" or "--to string".

func ParseFlags

func ParseFlags(usages string) []Flag

ParseFlags reads pflag's FlagUsages lines (" -y, --yes usage"); help is left out.

func (Flag) String

func (f Flag) String() string

type Help

type Help struct {
	Children []string
	Flags    []Flag
	Global   []Flag
}

Help is what one `--help` says: the visible subcommands and the flags.

func ParseHelp

func ParseHelp(text string) Help

ParseHelp reads cobra's default usage text.

type Tree

type Tree map[string]Command

Tree is every visible command by path.

func FromHelp

func FromHelp(root string, help func(words []string) (string, error)) (Tree, error)

FromHelp builds the tree by asking for help: help(path words) returns the text of `<program> <words...> --help`.

func (Tree) Golden

func (t Tree) Golden() string

Golden is the tree as the checked-in golden file has it: each command, then its own flags, sorted.

func (Tree) Resolve

func (t Tree) Resolve(root string, words []string) (Command, []string)

Resolve follows words from the root as far as they name subcommands: the command they reach and the words left.

Jump to

Keyboard shortcuts

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