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 Main(run func(ctx context.Context) int) int
- func Mistaken(command string, err error) error
- func Nearest(typed string, names []string) []string
- func NearestLine(kind, before string, near []string) string
- func NoArgument(set *flag.FlagSet) error
- func Notes(stderr io.Writer) io.Writer
- func OnInterrupt(need Interrupt) (forget func())
- func Parse(set *flag.FlagSet, args []string, stderr io.Writer) error
- func Plain(err error) string
- func Quiet(stderr io.Writer) bool
- func Say(stderr io.Writer, format string, args ...any)
- func Stopped(what string, then ...string) error
- func Under(stderr io.Writer) io.Writer
- func Usage(command string) string
- func Without(name string, err error) error
- type Block
- type Group
- type Interrupt
- type Lines
- type Messages
- 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 // ExitInterrupted: Ctrl-C ended the command. It is 128 and the number of // SIGINT, which a shell reports for a process the signal ended. ExitInterrupted = 130 )
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 QuietRow = Row{"-q, --quiet", "keep warnings and errors on standard error, and drop every other line"}
QuietRow is the flag's line under Flags on every help page.
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 Main ¶
Main runs a command and answers the code costroid exits with. SIGTERM ends the command's context, and the command ends as it chooses. Ctrl-C ends the context too, and costroid then exits ExitInterrupted, whatever the command answers, once the command has returned or the time it asked for has passed.
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 NoArgument ¶
NoArgument is the mistake of an argument where set's command takes none. It answers nil when the command line gave none.
func Notes ¶
Notes is where a command writes the lines --quiet drops: what it did, what it is about to wait for, and what to do next.
func OnInterrupt ¶
func OnInterrupt(need Interrupt) (forget func())
OnInterrupt records what a command needs when Ctrl-C reaches it, until the function it answers is called.
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. Parse gives every set --quiet, and under it stderr drops the lines that are neither a warning nor an error.
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 Under ¶
Under is the writer stderr was made from, which a child process is given so that it holds the file itself.
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 Interrupt ¶
type Interrupt struct {
// Wait is how long costroid waits for the command to return once its
// context has ended, which a command that holds a child process needs to
// stop it.
Wait time.Duration
// Doing says what the command does in that time, such as "stopping
// claude". It is printed at once.
Doing string
// Restore runs at once, for a command that changed the terminal.
Restore func()
// Own says the command ends on an interrupt by its own rule, as a
// service that drains does, and exits with its own code.
Own bool
}
Interrupt is what a command needs when Ctrl-C reaches it. The zero value asks for nothing: the command's context ends and costroid exits ExitInterrupted.
type Messages ¶
type Messages struct {
// contains filtered or unexported fields
}
Messages is a command's standard error. Standard output holds what a command was asked to print, and Messages holds what it says about its work. A warning or an error is written to it as to any writer, and stays under --quiet. Every other line goes through Say or Notes, and --quiet drops it.
func NewMessages ¶
NewMessages is the standard error of one command line, written to to.
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. String
// adds --quiet, which every command takes.
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.