commands

package
v0.2.22 Latest Latest
Warning

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

Go to latest
Published: May 4, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PackVersion = 1

	ScopeLocal  = "local"
	ScopeShared = "shared"

	StatusActive     = "active"
	StatusDisabled   = "disabled"
	StatusConflicted = "conflicted"

	StepTypeExec  = "exec"
	StepTypeShell = "shell"
)

Variables

This section is empty.

Functions

func Execute

func Execute(ctx context.Context, command Command, args []string, stdout, stderr io.Writer) error

Execute runs a command definition step by step.

func LocalPackPath

func LocalPackPath() (string, error)

LocalPackPath returns the user-local command pack path.

func RepoPackPath

func RepoPackPath(start string) (string, error)

RepoPackPath returns the shared pack path for the current repository.

func RepoRoot

func RepoRoot(start string) (string, error)

RepoRoot walks upward until it finds a git worktree root.

func SortCommands

func SortCommands(commands []ResolvedCommand)

SortCommands sorts commands by path for stable presentation.

Types

type Command

type Command struct {
	Path        []string  `json:"path"`
	Description string    `json:"description,omitempty"`
	Scope       string    `json:"scope"`
	Source      string    `json:"source,omitempty"`
	Enabled     bool      `json:"enabled"`
	Revision    int       `json:"revision"`
	CreatedAt   time.Time `json:"created_at"`
	UpdatedAt   time.Time `json:"updated_at"`
	Steps       []Step    `json:"steps"`
}

Command describes one automation command.

func PackSummary

func PackSummary(commands []Command) []Command

PackSummary returns a deterministic presentation order for commands.

func (Command) Clone

func (c Command) Clone() Command

Clone returns a deep copy of the command.

func (Command) DisplayName

func (c Command) DisplayName() string

DisplayName returns a user-friendly command path.

func (Command) Key

func (c Command) Key() string

Key returns the canonical command path.

func (*Command) Normalize

func (c *Command) Normalize(scope string, source string)

Normalize fills default metadata.

func (Command) Validate

func (c Command) Validate() error

Validate checks a single command definition.

type Pack

type Pack struct {
	Version  int       `json:"version"`
	Commands []Command `json:"commands"`
}

Pack stores a complete command collection.

func LoadPackFile

func LoadPackFile(path string) (Pack, error)

LoadPackFile loads a command pack from disk.

func (*Pack) AddCommand

func (p *Pack) AddCommand(command Command, scope string, source string) error

AddCommand appends a command to the pack after normalizing it.

func (*Pack) DeleteCommand

func (p *Pack) DeleteCommand(path []string) bool

DeleteCommand removes a command from the pack by path.

func (*Pack) EnsureVersion

func (p *Pack) EnsureVersion()

EnsureVersion sets the pack version if needed.

func (Pack) FindCommand

func (p Pack) FindCommand(path []string) (Command, bool)

FindCommand returns a command by path.

func (Pack) Save

func (p Pack) Save(path string) error

Save writes the pack to disk using a stable JSON encoding.

func (*Pack) UpdateCommand

func (p *Pack) UpdateCommand(path []string, fn func(*Command) error) error

UpdateCommand updates an existing command by path.

func (Pack) Validate

func (p Pack) Validate() error

Validate checks a pack for malformed commands.

type ResolvedCommand

type ResolvedCommand struct {
	Command        Command `json:"command"`
	Status         string  `json:"status"`
	ConflictReason string  `json:"conflict_reason,omitempty"`
}

ResolvedCommand annotates a command with its runtime state.

type Step

type Step struct {
	Type    string            `json:"type"`
	Dir     string            `json:"dir,omitempty"`
	Env     map[string]string `json:"env,omitempty"`
	Command []string          `json:"command,omitempty"`
	Script  string            `json:"script,omitempty"`
}

Step describes one command action.

func (Step) Clone

func (s Step) Clone() Step

Clone returns a deep copy of a step.

func (Step) Validate

func (s Step) Validate() error

Validate checks one step definition.

type Workspace

type Workspace struct {
	Cwd       string
	LocalPath string
	RepoPath  string
	Local     Pack
	Repo      Pack
}

Workspace represents local and repo-shared command packs together.

func LoadWorkspace

func LoadWorkspace(cwd string) (*Workspace, error)

LoadWorkspace loads the current user's command packs.

func (*Workspace) ActiveCommands

func (w *Workspace) ActiveCommands(reserved [][]string) []ResolvedCommand

ActiveCommands returns commands that can be registered with Cobra.

func (*Workspace) AddCommand

func (w *Workspace) AddCommand(command Command, scope string) error

AddCommand stores a command in the requested scope.

func (*Workspace) DeleteCommand

func (w *Workspace) DeleteCommand(path []string, scope string) bool

DeleteCommand removes a command from the requested scope.

func (*Workspace) ResolvedCommands

func (w *Workspace) ResolvedCommands(reserved [][]string) []ResolvedCommand

ResolvedCommands returns all commands with state annotations.

func (*Workspace) Save

func (w *Workspace) Save() error

Save persists both packs where available.

func (*Workspace) SaveLocal

func (w *Workspace) SaveLocal() error

SaveLocal persists the local pack.

func (*Workspace) SaveRepo

func (w *Workspace) SaveRepo() error

SaveRepo persists the repo pack when a repository exists.

func (*Workspace) UpdateCommand

func (w *Workspace) UpdateCommand(path []string, scope string, fn func(*Command) error) error

UpdateCommand updates a command in the requested scope.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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