Documentation
¶
Overview ¶
Package shellparse extracts individual commands from shell one-liners.
It uses mvdan.cc/sh/v3/syntax to parse shell scripts into an AST, then walks the tree to collect every simple command along with its redirects. Compound constructs (&&, ||, ;, |, for, while, if, case, subshells, command substitutions) are recursively decomposed so that every leaf command is reported individually.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ParseResult ¶
type ParseResult struct {
// Commands contains all individual commands found in the input.
Commands []ParsedCommand
// Original is the input string that was parsed.
Original string
}
ParseResult holds the complete result of parsing a shell one-liner.
func Parse ¶
func Parse(input string) *ParseResult
Parse decomposes a shell one-liner into individual commands.
It handles:
- Command separators: &&, ||, ;, &, | (pipe)
- Control structures: for, while, until, if/elif/else, case
- Grouping: (...) subshells, {...} blocks
- Command substitution: $(...) and backticks (recursively)
- Redirections: >, >>, 2>, &>, 2>&1, <, etc.
On parse failure the entire input is returned as a single command (fallback).
type ParsedCommand ¶
type ParsedCommand struct {
// Raw is the reconstructed command string (e.g. "git status").
Raw string
// Executable is the command name (e.g. "git").
Executable string
// Args contains the arguments after the executable (e.g. ["status"]).
Args []string
// Redirects lists file redirections attached to this command.
Redirects []Redirect
}
ParsedCommand represents a single simple command extracted from a one-liner.