cli

package
v1.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 18, 2026 License: MIT Imports: 21 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package cli provides Sidecar's non-interactive command dispatch boundary.

Index

Constants

View Source
const ConfigPageSetup = "setup"

ConfigPageSetup is the Configuration destination `sidecar setup` asks for. The app treats an unknown name as "the default page", which is what keeps the plumbing usable by a future caller that names a different one.

Variables

This section is empty.

Functions

func RemainingArgs added in v1.0.0

func RemainingArgs(args []string) []string

RemainingArgs is what the process should parse as flags after Run returns handled=false. A launch command consumes its own name, so `sidecar setup -project /x` parses -project exactly as `sidecar -project /x` does.

func RenderAgents added in v1.0.0

func RenderAgents(root *Command) string

RenderAgents lists what an agent can do from Sidecar. It is generated from the same registry the help and the reference doc come from, so a command that grows an agent-facing use appears here by declaring it, not by someone remembering to update a list.

func RenderHelp added in v1.0.0

func RenderHelp(cmd *Command) string

RenderHelp returns the formatted help string for a command.

func RenderJSON added in v1.0.0

func RenderJSON(w io.Writer, cmd *Command) error

RenderJSON writes the JSON representation of a command tree to w.

func RenderMarkdownDoc added in v1.0.0

func RenderMarkdownDoc(root *Command) string

RenderMarkdownDoc generates reference markdown documentation for the CLI command tree.

func Run

func Run(args []string, stdout, stderr io.Writer) (handled bool, exitCode int)

Run dispatches a non-interactive command. handled=false leaves legacy TUI flag parsing entirely untouched.

func StartupConfigPage added in v1.0.0

func StartupConfigPage() (string, bool)

StartupConfigPage reports the Configuration destination a launch command recorded, if any. main passes it to the app; nothing else reads it.

Types

type AgentDoc added in v1.0.0

type AgentDoc struct {
	Invocation string `json:"invocation,omitempty"`
	Summary    string `json:"summary,omitempty"`
}

AgentDoc is a command's agent-facing summary: an invocation and why it helps.

type ArgSpec added in v1.0.0

type ArgSpec struct {
	Min         int    `json:"min"`
	Max         int    `json:"max"` // -1 for unbounded
	Description string `json:"description,omitempty"`
}

ArgSpec specifies positional argument requirements.

type Command added in v1.0.0

type Command struct {
	Name      string                  `json:"name"`
	Summary   string                  `json:"summary"`
	Usage     string                  `json:"usage"`
	Long      string                  `json:"long,omitempty"`
	Targets   []TargetDoc             `json:"targets,omitempty"`
	Flags     []Flag                  `json:"flags,omitempty"`
	Args      ArgSpec                 `json:"args,omitempty"`
	ExitCodes []ExitCode              `json:"exitCodes,omitempty"`
	Examples  []Example               `json:"examples,omitempty"`
	Sub       []*Command              `json:"subcommands,omitempty"`
	Run       func(Env, []string) int `json:"-"`

	// Launch is for a command that does not run non-interactively at all: it
	// records what the app should do and hands the process back to normal
	// startup by reporting handled=false. `sidecar setup` is the only one — it
	// starts Sidecar the ordinary way with Configuration open, rather than
	// printing a second settings interface into the terminal.
	Launch func(Env, []string) (handled bool, exitCode int) `json:"-"`

	// Agent is what `sidecar --agents` says about this command: the one line an
	// agent needs to decide whether to reach for it. Commands without one are
	// left out of that list, so it stays a short list of things worth doing
	// rather than a second copy of the help.
	Agent AgentDoc `json:"agent,omitempty"`
}

Command is a declarative command definition.

func RootCommand added in v1.0.0

func RootCommand() *Command

RootCommand returns the root command hierarchy.

func (*Command) FindSubcommand added in v1.0.0

func (c *Command) FindSubcommand(name string) *Command

FindSubcommand looks up a direct child subcommand by name.

type Env added in v1.0.0

type Env struct {
	Stdout   io.Writer
	Stderr   io.Writer
	StateDir string
	Ctx      context.Context
}

Env holds the execution environment passed to a command handler.

type Example added in v1.0.0

type Example struct {
	Description string `json:"description,omitempty"`
	Command     string `json:"command"`
}

Example illustrates command usage.

type ExitCode added in v1.0.0

type ExitCode struct {
	Code    int    `json:"code"`
	Summary string `json:"summary"`
}

ExitCode describes a command exit status.

type Flag added in v1.0.0

type Flag struct {
	Name    string `json:"name"`
	Short   string `json:"short,omitempty"`
	Arg     string `json:"arg,omitempty"`
	Summary string `json:"summary"`
	Bool    bool   `json:"bool,omitempty"`
}

Flag defines a command line flag.

type TargetDoc added in v1.0.0

type TargetDoc struct {
	Target  string `json:"target"`
	Summary string `json:"summary"`
}

TargetDoc describes target formats for commands like open.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL