cli

package
v0.0.0-...-6f58290 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2026 License: MIT Imports: 26 Imported by: 0

Documentation

Overview

Package cli builds the urfave/cli/v3 command tree for the bagit binary.

Commands are constructed via factory functions that take a Deps struct so tests can swap I/O streams, the working directory, and the clock without touching globals.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewAICommand

func NewAICommand(deps Deps) *cli.Command

NewAICommand builds `bagit ai` with `list` and `<action> <id>` forms.

Action definitions live in `[ai.actions.<name>]` config blocks. The args support {item_path}, {item_dir}, {item_id}, {title} substitution before being passed to the configured command. Stdout/stderr/stdin are wired straight through so users see the tool's output live.

func NewAssetsCommand

func NewAssetsCommand(deps Deps) *cli.Command

NewAssetsCommand builds `bagit assets <id>`.

func NewAttachCommand

func NewAttachCommand(deps Deps) *cli.Command

NewAttachCommand builds `bagit attach <id> <path>` and the `attach rm` subcommand for removing an attachment by name.

func NewBodyCommand

func NewBodyCommand(deps Deps) *cli.Command

NewBodyCommand builds `bagit body <id>`. It lets agents and scripts read or replace the markdown body of an item without spawning $EDITOR.

Resolution order for the new body content:

  1. -m/--message string flag.
  2. -f/--file path flag (use "-" for stdin).
  3. Trailing positional args joined with spaces.
  4. Buffered stdin in tests. In production, use -f - for stdin.

If no input is provided, the existing body is written to stdout. The `--append` flag preserves the existing body and appends a blank line plus the new content.

func NewCommentCommand

func NewCommentCommand(deps Deps) *cli.Command

NewCommentCommand builds `bagit comment <id> [body]`. If body is omitted and stdin is not a TTY, the comment body is read from stdin. Otherwise, --message must be supplied. The author defaults to the GIT_AUTHOR or USERNAME env vars.

func NewCommentsCommand

func NewCommentsCommand(deps Deps) *cli.Command

NewCommentsCommand builds `bagit comments <id>`.

func NewConfigCommand

func NewConfigCommand(deps Deps) *cli.Command

NewConfigCommand builds `bagit config` with `get` / `set` / `show`.

func NewEditCommand

func NewEditCommand(deps Deps) *cli.Command

NewEditCommand builds `bagit edit <id>`. It opens the item.md in the resolved editor and refreshes the Updated stamp on success.

func NewInitCommand

func NewInitCommand(deps Deps) *cli.Command

NewInitCommand builds the `bagit init` subcommand. Init scaffolds the `.bagit/` directory (config, tags registry, items dir), refreshes the repo-root AGENTS.md block, updates `.gitignore`, and optionally writes tool-specific skill files. On a TTY it asks questions to seed config; non-TTY runs and `--yes` use the supplied defaults / overrides.

func NewListCommand

func NewListCommand(deps Deps) *cli.Command

NewListCommand builds `bagit list`.

`list` is the no-query degenerate case of `search`: it shares the same structured filters and output renderers, and delegates filtering to search.ApplyFilter so there is a single source of truth for the OR-within-field / AND-across-fields semantics.

func NewMvCommand

func NewMvCommand(deps Deps) *cli.Command

NewMvCommand builds `bagit mv <id> <status>`.

func NewNewCommand

func NewNewCommand(deps Deps) *cli.Command

NewNewCommand builds `bagit new <title>`. With no title argument on a TTY (and without --yes) it launches a small huh form to scaffold the item; otherwise it stays non-interactive and behaves as before.

func NewOpenCommand

func NewOpenCommand(deps Deps) *cli.Command

NewOpenCommand builds `bagit open <id>`. It opens the item directory using the platform's default file/URL handler so the user can browse assets, attach files, etc.

func NewPathCommand

func NewPathCommand(deps Deps) *cli.Command

NewPathCommand builds `bagit path <id>`. It prints the absolute path to the item.md file, suitable for use in shell pipelines (e.g. `code $(bagit path 42)`).

func NewRmCommand

func NewRmCommand(deps Deps) *cli.Command

NewRmCommand builds `bagit rm <id>`. Deletion is a hard remove of the item directory; the user must confirm interactively unless --yes is set.

func NewRootCommand

func NewRootCommand(deps Deps) *cli.Command

NewRootCommand constructs the top-level `bagit` command with all subcommands attached.

func NewSearchCommand

func NewSearchCommand(deps Deps) *cli.Command

NewSearchCommand builds `bagit search [query]`.

func NewShowCommand

func NewShowCommand(deps Deps) *cli.Command

NewShowCommand builds `bagit show <id>`.

func NewSkillsCommand

func NewSkillsCommand(deps Deps) *cli.Command

NewSkillsCommand builds `bagit skills` with install/regenerate subcommands. Both write tool-specific skill files for OpenCode, Claude, Cursor, and Copilot. `install` defaults to auto-detecting tools when --for and positional tool names are omitted.

func NewStatsCommand

func NewStatsCommand(deps Deps) *cli.Command

NewStatsCommand builds `bagit stats`.

func NewStatusShortcutCommand

func NewStatusShortcutCommand(deps Deps, name string, target store.Status, usage string) *cli.Command

NewStatusShortcutCommand builds the `start`, `done`, and `reopen` shortcuts that move an item directly to a fixed status.

func NewTUICommand

func NewTUICommand(deps Deps) *cli.Command

NewTUICommand builds `bagit i` (aliases: `interactive`, `tui`). It launches the bubbletea-driven TUI rooted at the resolved bagit repo.

func NewTagCommand

func NewTagCommand(deps Deps) *cli.Command

NewTagCommand builds `bagit tag` and its subcommands. Top-level invocation (`bagit tag`) lists known tags from the registry; item tag mutations grow the registry, and explicit `add` lets users seed metadata up front.

func NewTemplatesCommand

func NewTemplatesCommand(deps Deps) *cli.Command

NewTemplatesCommand builds `bagit templates` with `eject` and `reset` subcommands. Templates are the embedded markdown bodies used when creating new items via `bagit new`; ejecting writes them to .bagit/templates/<t>.md for user editing, and resetting deletes the override so the embedded version takes over again.

func NewValidateCommand

func NewValidateCommand(deps Deps) *cli.Command

NewValidateCommand builds `bagit validate`. It walks .bagit/items and reports unparseable directories, malformed item.md files, duplicate ids, slug drift, broken xrefs, missing asset references, and unknown tags.

func NewXrefCommand

func NewXrefCommand(deps Deps) *cli.Command

NewXrefCommand builds `bagit xref [id]`. With no id, it lists every cross-reference in the backlog. With an id, it lists the inbound and outbound xrefs for that item.

func Run

func Run(ctx context.Context, deps Deps, args []string) int

Run executes the CLI with the given args. It maps errors to exit codes:

0  success
1  user error (validation, bad args, "not found")
2  system error (I/O, internal failures)

Suitable for direct use from cmd/bagit/main.go.

Types

type Deps

type Deps struct {
	WorkingDir string
	Stdout     io.Writer
	Stderr     io.Writer
	Stdin      io.Reader
	// IsTTY reports whether stdout is connected to a terminal. When nil,
	// commands assume false (safe default for piping).
	IsTTY func() bool
}

Deps carries per-invocation dependencies for command actions. A zero-value Deps with the working directory set is sufficient for production use; tests override Stdout, Stderr, Stdin, and the working directory as needed.

type Stats

type Stats struct {
	Total      int            `json:"total"`
	ByStatus   map[string]int `json:"by_status"`
	ByType     map[string]int `json:"by_type"`
	ByTag      map[string]int `json:"by_tag"`
	Comments   int            `json:"comments"`
	WithAssets int            `json:"with_assets"`
}

Stats summarizes the backlog in numeric form.

type ValidationIssue

type ValidationIssue struct {
	Path    string `json:"path"`
	ID      int    `json:"id,omitempty"`
	Kind    string `json:"kind"`
	Message string `json:"message"`
}

ValidationIssue is one problem found by `bagit validate`.

Jump to

Keyboard shortcuts

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