Documentation
¶
Overview ¶
Package clihelp is the machine-readable shape of `skywire cli --help`.
`--help --json` emits this instead of the rendered help text. The point is discovery without scraping: one call at the root returns the whole command tree with every flag, its type and its default, so a caller can find the command it needs — or check what a flag is called — without running 387 commands and parsing prose that was written for a person.
Cobra offers nothing here. It renders help through a text/template and has no notion of a machine format (there is no JSON anywhere in the library), so the schema is ours to define. What it does offer is SetHelpFunc, which children inherit — so registering once on the root covers every subcommand.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Command ¶
type Command struct {
// Name is the first word of Use; Path is how you would type it,
// e.g. "skywire cli visor info". Both are given because callers want
// different ones: Name to match, Path to run.
Name string `json:"name"`
Path string `json:"path"`
Use string `json:"use,omitempty"`
Short string `json:"short,omitempty"`
Long string `json:"long,omitempty"`
Example string `json:"example,omitempty"`
Aliases []string `json:"aliases,omitempty"`
Deprecated string `json:"deprecated,omitempty"`
Hidden bool `json:"hidden,omitempty"`
// Runnable distinguishes a command that does something from a group that
// only holds subcommands.
Runnable bool `json:"runnable"`
// Flags are declared on this command; Inherited come from ancestors
// (--json among them). Kept apart because the distinction decides where
// a flag may be placed on the command line.
Flags []Flag `json:"flags,omitempty"`
Inherited []Flag `json:"inherited_flags,omitempty"`
Subcommands []Command `json:"subcommands,omitempty"`
}
Command is one command and, recursively, everything under it.
type Flag ¶
type Flag struct {
Name string `json:"name"`
// Shorthand is the single-letter form without its dash, empty if none.
Shorthand string `json:"shorthand,omitempty"`
// Type is pflag's own name for the value: "string", "bool", "int",
// "stringSlice" and so on. It is what tells a caller whether the flag
// takes an argument.
Type string `json:"type"`
Default string `json:"default,omitempty"`
Usage string `json:"usage,omitempty"`
Deprecated string `json:"deprecated,omitempty"`
Hidden bool `json:"hidden,omitempty"`
}
Flag is one flag as the parser sees it.
type Node ¶
type Node struct {
Name string `json:"name"`
// Path is how the command is typed, e.g. "skywire cli visor info".
Path string `json:"path"`
// Runnable separates a command that does something from a group that only
// holds others — the distinction the ASCII rendering cannot show.
Runnable bool `json:"runnable"`
Children []Node `json:"children,omitempty"`
}
Node is the command tree with the help text stripped out: what `tree` shows, in the shape a program would want it.
Deliberately not Command. `tree` exists to show STRUCTURE — it is `help -t`, help with the text removed — so its JSON carries names and nesting and nothing else. Emitting the full Command schema here would make `tree --json` a duplicate of `--help --json`, and the two commands would stop meaning different things.