Documentation
¶
Overview ¶
Package cli provides shared types and utilities for CLI commands. This package is designed to be imported by both cmd/moat/cli and internal/providers/*/cli.go to avoid import cycles.
IMPORTANT: This package MUST NOT import internal/run or internal/providers to avoid import cycles. Only put types and utility functions here that don't depend on the run or provider packages.
Index ¶
- Variables
- func AddExecFlags(cmd *cobra.Command, flags *ExecFlags)
- func FormatTimeAgo(t time.Time) string
- func HasDependency(deps []string, prefix string) bool
- func ParseEnvFlags(envFlags []string, cfg *config.Config) error
- func ResolveWorkspacePath(workspace string) (string, error)
- func SetWorktreeFields(opts *ExecOptions, wt *worktree.Result)
- func ShortenPath(path string) string
- type ExecFlags
- type ExecOptions
- type ExecResult
- type RunInfo
- type WorktreeResult
Constants ¶
This section is empty.
Variables ¶
var ( // DryRun is set by the --dry-run flag DryRun bool // RootCmd is the root cobra command, needed for providers to add subcommands RootCmd *cobra.Command // ExecuteRun is the function that executes a containerized command. // This is set by cmd/moat/cli to avoid import cycles. // It accepts ExecOptions and returns (*ExecResult, error). ExecuteRun func(ctx context.Context, opts ExecOptions) (*ExecResult, error) // CheckWorktreeActive checks if there is a running run in the given worktree path. // Returns the run name and ID if active, or empty strings if not. // This is set by cmd/moat/cli to avoid import cycles. CheckWorktreeActive func(worktreePath string) (name, id string) )
Global state that providers need access to. These are set by cmd/moat/cli/root.go during initialization.
Functions ¶
func AddExecFlags ¶
AddExecFlags adds the common execution flags to a command.
func FormatTimeAgo ¶ added in v0.2.0
FormatTimeAgo formats a time as a human-readable "ago" string.
func HasDependency ¶
HasDependency checks if a dependency prefix exists in the list. Matches exact name (e.g., "node") or name with version (e.g., "node@20").
func ParseEnvFlags ¶
ParseEnvFlags validates and parses environment variable flags into the config.
func ResolveWorkspacePath ¶
ResolveWorkspacePath resolves and validates a workspace path argument. Returns the absolute, symlink-resolved path.
func SetWorktreeFields ¶ added in v0.2.0
func SetWorktreeFields(opts *ExecOptions, wt *worktree.Result)
SetWorktreeFields copies worktree metadata from a Result into ExecOptions.
func ShortenPath ¶ added in v0.2.0
ShortenPath shortens a path for display by replacing the home directory with ~.
Types ¶
type ExecFlags ¶
type ExecFlags struct {
Grants []string
Env []string
Name string
Runtime string
Rebuild bool
KeepContainer bool
Detach bool
Interactive bool
NoSandbox bool
TTYTrace string // Path to save terminal I/O trace for debugging
}
ExecFlags holds the common flags for container execution commands. These are shared between `moat run`, `moat claude`, and future tool commands.
type ExecOptions ¶
type ExecOptions struct {
// From flags
Flags ExecFlags
// Command-specific
Workspace string
Command []string
Config *config.Config
Interactive bool // Can be set by flags or command logic
TTY bool
// Worktree tracking (set by moat wt or --wt flag)
WorktreeBranch string
WorktreePath string
WorktreeRepoID string
// Callbacks for command-specific behavior
// OnRunCreated is called after run is created, before start.
// The RunInfo parameter contains the run's ID and Name.
OnRunCreated func(info RunInfo)
}
ExecOptions contains all the options needed to execute a containerized command.
type ExecResult ¶
ExecResult contains the result of executing a run. This is returned instead of *run.Run to avoid import cycles.
type RunInfo ¶
RunInfo contains minimal information about a run, extracted to avoid import cycles. This is passed to callbacks instead of the full *run.Run type.
type WorktreeResult ¶ added in v0.2.0
type WorktreeResult struct {
// Workspace is the absolute path to use (worktree path if --wt was set,
// or the original workspace if not).
Workspace string
// Config is the config to use (reloaded from worktree if it has its own
// agent.yaml, or the original config if not).
Config *config.Config
// Result is the worktree resolution metadata (nil if --wt was not set).
Result *worktree.Result
}
WorktreeResult holds the outcome of ResolveWorktreeWorkspace. It bundles the resolved workspace path and updated config together so callers don't need to handle feedback, config reloading, or active run detection themselves.
func ResolveWorktreeWorkspace ¶ added in v0.2.0
func ResolveWorktreeWorkspace(wtBranch, workspace string, flags *ExecFlags, cfg *config.Config) (*WorktreeResult, error)
ResolveWorktreeWorkspace handles the --wt flag for provider commands. If wtBranch is empty, returns the original workspace and config unchanged. Otherwise, resolves the worktree, checks for active runs, prints user feedback, reloads config from the worktree if available, and sets the run name on flags.