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 ¶
- Variables
- func CheckDocumented(t Tree, files map[string][]byte, allowed Allowed) []string
- func CheckSkill(t Tree, root string, files map[string][]byte) []string
- func Diff(want, got string) string
- func Documented(files map[string][]byte) map[string]bool
- func Undocumented(t Tree, files map[string][]byte) []string
- type Allowed
- type Command
- type Flag
- type Help
- type Tree
Constants ¶
This section is empty.
Variables ¶
var Skip = map[string]bool{"help": true, "completion": true}
Skip are commands left out of the tree everywhere: cobra's own.
Functions ¶
func CheckDocumented ¶
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 ¶
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 ¶
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 ¶
Documented is every --flag the skill files name anywhere.
Types ¶
type Allowed ¶
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 ¶
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.
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 ¶
ParseFlags reads pflag's FlagUsages lines (" -y, --yes usage"); help is left out.