Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ArgWords ¶
ArgWords returns every word of every simple command in a line, which is what a rule about the line's arguments needs to consider. Assignment prefixes are not words and are not included.
func HasPipe ¶
HasPipe reports whether a line joins commands with a pipe, which is what decides whether a bare `-` argument is fed by an upstream command or would sit reading the session's empty stdin. A pipe character inside a quoted argument is not one, which is the reason this asks the parse rather than the string.
func MatchesWords ¶
MatchesWords reports whether a line contains the match text as a run of consecutive whole words. Both sides are read as shell, so quoting is resolved the same way on each and a match written the way the document writes it selects the same line. When either side does not parse, the comparison falls back to a substring, which is the old behavior and the only thing left to do with text no parser can read.
func Operands ¶
Operands returns every word of a line that is not a command name, so a rule about a line's arguments never trips over the program itself. A tool named `pattern` is the command in `pattern build` and a placeholder in `tool build pattern`, and only the position separates them.
Types ¶
type Cmd ¶
type Cmd struct {
// Assigns are the NAME=value prefixes attached to this command.
Assigns []string
// Words are the command and its arguments, one word per argument, with
// quoting resolved. A word whose value depends on an expansion keeps the
// expansion's source text, since its real value is unknown until it runs.
Words []string
// Expanded marks a command holding a substitution or expansion whose
// value kibble cannot know without running it.
Expanded bool
}
Cmd is one simple command from a documented line, with its words as the shell would split them.
type Line ¶
type Line struct {
// Cmds are the simple commands the line runs, in source order, including
// those inside pipelines, lists, subshells, and compound statements.
Cmds []Cmd
// Structured marks a line that is more than one simple command: a
// pipeline, a list, a redirect, a subshell, a loop, or a conditional.
Structured bool
// StateChanging marks a line whose effect is on the shell itself, so
// running it anywhere but the session's own shell would lose that effect.
// A bare assignment, a cd, an export, a source, and their relatives all
// qualify, wherever they appear in the line.
StateChanging bool
// Heredoc marks a line carrying a here-document body.
Heredoc bool
// Background marks a line the document itself puts in the background.
Background bool
}
Line is a parsed documented line.