Documentation
¶
Overview ¶
Package cli holds what every costroid command shares on the command line: the shape of a help page, what a mistake and an error print, and the codes a command exits with.
Index ¶
- Constants
- Variables
- func Explain(stderr io.Writer, err error)
- func Fail(stderr io.Writer, err error) int
- func File(err error) error
- func Mistaken(command string, err error) error
- func Nearest(typed string, names []string) []string
- func NearestLine(kind, before string, near []string) string
- func Parse(set *flag.FlagSet, args []string) error
- func Plain(err error) string
- func Stopped(what string, then ...string) error
- func Usage(command string) string
- func Without(name string, err error) error
- type Block
- type Group
- type Lines
- type Mistake
- type Page
- type Row
- type Rows
- type Section
- type Text
Constants ¶
const ( // ExitDone: the command did its work, and a verdict is success or neutral. ExitDone = 0 // ExitFailed: the command did its work and the answer is a failure. ExitFailed = 1 // ExitUsage: the command line is wrong. ExitUsage = 2 // ExitCapped: run stopped the agent at the cap. ExitCapped = 124 // ExitCouldNot: costroid could not do its work. ExitCouldNot = 125 )
The codes a costroid command exits with, one for each way a command ends. No command picks a number of its own. costroid run passes the agent's code through, so every code below ExitCapped is the agent's there, and a wrong command line of run itself exits ExitCouldNot.
const ( // Width is the widest line a help page prints. Width = 80 // Documentation is the address every page's own address starts with. Documentation = "https://docs.costroid.com" )
const Troubleshooting = Documentation + "/troubleshooting"
Troubleshooting is the page that lists the lines costroid prints.
Variables ¶
var UsageExit = Row{"2", "the command line is wrong"}
UsageExit is the row every command's help lists for ExitUsage. run's lists none: its own wrong command line exits ExitCouldNot.
Functions ¶
func Explain ¶
Explain prints what stopped a command, under costroid's name: what is wrong on the first line, then why and what to do next when the error says them. An error that names no next step ends on the page that lists costroid's lines.
func Fail ¶
Fail explains err and answers the code its command exits with: ExitUsage for a command line that is wrong, ExitCouldNot for anything else.
func File ¶
File is err said by the file it ends on, when it ends on one: "read a workflow: stat x: no such file or directory" reads "x does not exist". It is for a file the user named, where what each caller put before the file names a step of the program and not the thing that is wrong.
func Mistaken ¶
Mistaken says the command line of command is wrong for the reason err gives: an argument too many, a required flag left out, a value of the wrong form. The lines end on where the command's usage is. An error that is already a Mistake comes back as it is, and so does a request for help, which is no mistake.
func Nearest ¶
Nearest answers the names among names that typed most likely stands for, or none when none is near: the names one edit away, or else, for a word of five letters or more, the names two edits away, and otherwise the one name typed opens.
func NearestLine ¶
NearestLine names what is nearest to a mistyped word as one sentence: kind is command or flag, and before stands before each name. It is empty when near is.
func Parse ¶
Parse parses args with set and prints nothing. It answers flag.ErrHelp when help was asked for and a *Mistake when a flag was refused; the caller prints either. The set's name is the command's, with its subcommand when it has one.
func Plain ¶
Plain is err's text with what the system said put in words. Go names the call and its error, as in "open rows.jsonl: no such file or directory" or `Get "https://host/path": dial tcp 127.0.0.1:443: connect: connection refused`, and a reader named the file or the host, never the call.
func Stopped ¶
Stopped is work a command could not do: what is wrong, then why when costroid knows it or the choices the reader has, then what to do next. A line of why or of what to do is a sentence, and the last line names a command, a file or a page.
func Usage ¶
Usage is the line that says where the usage of command is, which a command's own finding about its command line ends on.
Types ¶
type Block ¶
type Block interface {
// contains filtered or unexported methods
}
Block is one piece of a section: Text, Rows or Lines.
type Group ¶
type Group struct {
Command string
// Summary is one sentence, the one the command's Page opens with.
Summary string
Subcommands []Row
// Example is one command line, on as many lines as it needs.
Example []string
}
Group is the short page of a command that takes a subcommand, which a call with none prints: what the command does, each subcommand with what it does, one call to copy and where the whole page is.
type Mistake ¶
type Mistake struct {
// contains filtered or unexported fields
}
Mistake is a command line that is wrong: a flag the command does not have, a flag without its value, a value of the wrong form, an argument too many or one left out. Its text opens with what was typed and what is wrong with it, then names the nearest name the command has, when one is near, and the command's help. A command that stops on one exits ExitUsage.
type Page ¶
type Page struct {
// Command names the exit code table.
Command string
// Summary is one sentence.
Summary string
// Usage holds one line per element. A form too long for one line goes on
// in the next element, which opens with the spaces that align it.
Usage []string
// Examples are command lines to run as written, the commonest first.
Examples []string
// Flags gives each flag, with its value's name, and what it does.
Flags []Row
Sections []Section
// Environment says what the command reads from the environment.
Environment []Block
Exits []Row
// Docs is the command's page under Documentation.
Docs string
}
Page is one command's help. String prints its parts in one order: what the command does, how it is called, calls to copy, its flags, whatever else the command needs said, what it reads from the environment, its exit codes and the address of its page in the documentation.