Help us shape the future of Go! Take the 2026 Go Developer Survey

cmdutil

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package cmdutil provides shared helpers for CLI command implementations.

Index

Constants

This section is empty.

Variables

View Source
var ErrAlreadyWritten = errors.New("error already written to output")

ErrAlreadyWritten signals that a JSON error envelope was already written.

Functions

func LoadRegistry

func LoadRegistry(vaultPath string) (*schema.Registry, error)

LoadRegistry loads only the type registry from a vault's .vaultmind/config.yaml without opening the index database. Use this when you need schema information (e.g., for live validation) but not the index itself.

func WriteJSON

func WriteJSON(w io.Writer, command string, result interface{}, vaultPath, indexHash string) error

WriteJSON writes a JSON envelope to the writer.

func WriteJSONError

func WriteJSONError(w io.Writer, command, code, message string) error

WriteJSONError writes a JSON error envelope to the writer.

Types

type VaultDB

type VaultDB struct {
	DB     *index.DB
	Config *vault.Config
	Reg    *schema.Registry
	// contains filtered or unexported fields
}

VaultDB bundles the commonly needed vault resources.

func OpenVaultDB

func OpenVaultDB(vaultPath string) (*VaultDB, error)

OpenVaultDB loads config, opens the index DB, and creates the type registry.

func OpenVaultDBOrWriteErr

func OpenVaultDBOrWriteErr(cmd *cobra.Command, vaultPath, commandName string) (*VaultDB, error)

OpenVaultDBOrWriteErr opens the vault DB. On failure with --json set, writes a JSON error envelope and returns ErrAlreadyWritten.

When no vault was named — no --vault, no VAULTMIND_VAULT — the path is whatever discovery fell back to, normally the working directory. Opening a non-vault directory in that case is wrong twice over: the command answers from a vault the user never chose (reporting "ok" and zero hits, which reads as "your vault has nothing on this" rather than "you have no vault"), and OpenVaultDB CREATES .vaultmind/index.db there on the way — quietly promoting that directory to a vault that every future walk-up will find. So a guessed path must prove it is already a vault before it is opened, while a named one keeps the permissive behaviour that lets any directory serve as a vault.

func (*VaultDB) Close

func (v *VaultDB) Close()

Close releases the database connection.

func (*VaultDB) GetIndexHash

func (v *VaultDB) GetIndexHash() string

GetIndexHash returns the cached SHA-256 hash of the SQLite database file.

func (*VaultDB) IndexHash

func (v *VaultDB) IndexHash() string

IndexHash computes the SHA-256 hash of the SQLite database file. Uses streaming hash to avoid loading the entire file into memory.

Jump to

Keyboard shortcuts

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