Documentation
¶
Overview ¶
Package cli provides utilities for building and managing Cobra commands.
Index ¶
- Variables
- func Config(cmd *cobra.Command) (*config.Config, error)
- func HookCheckIfDatabaseInitialized(cmd *cobra.Command, _ []string) error
- func HookEnsureDatabase(cmd *cobra.Command, args []string) error
- func HookEnsureGitEnv(cmd *cobra.Command, args []string) error
- func HookGitSync(cmd *cobra.Command, args []string) error
- func HookHelp(cmd *cobra.Command, _ []string) error
- func PrettyVersion(appName, version string) string
- type Hook
Constants ¶
This section is empty.
Variables ¶
var ( // SkipDBCheckAnnotation is used in subcmds declarations to skip the database // existence check. SkipDBCheckAnnotation = map[string]string{"skip-db-check": "true"} )
Functions ¶
func HookCheckIfDatabaseInitialized ¶
HookCheckIfDatabaseInitialized checks if database file exists and is initialized. Returns error if database already exists to prevent accidental re-initialization.
func HookEnsureDatabase ¶
HookEnsureDatabase ensures the database exists before command execution. Skips check for unlock operations and commands annotated with "skip-db-check". Returns an error if database is missing, locked, or needs initialization.
func HookEnsureGitEnv ¶
HookEnsureGitEnv ensures Git environment is properly set up. Shows help if help flags are present, verifies Git is installed, and checks if repository is initialized (except for init/import commands).
func HookGitSync ¶
HookGitSync synchronizes Git repository with current database state.
func PrettyVersion ¶
PrettyVersion formats version in a pretty way.
Types ¶
type Hook ¶
Hook is the function signature used for Cobra PersistentPreRunE hooks. It takes the current command and its arguments, and returns an error if the pre-run checks fail.
func ChainHooks ¶
ChainHooks chains multiple Hook functions into a single PersistentPreRunE. Hooks run in the order provided. The first non-nil error stops execution.
func HookInjectConfig ¶
HookInjectConfig returns a hook that injects the config into the command context.