cli

package
v0.1.31 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2026 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Overview

Package cli provides utilities for building and managing Cobra commands.

Index

Constants

This section is empty.

Variables

View Source
var (
	// SkipDBCheckAnnotation is used in subcmds declarations to skip the database
	// existence check.
	SkipDBCheckAnnotation = map[string]string{"skip-db-check": "true"}
)

Functions

func Config

func Config(cmd *cobra.Command) (*config.Config, error)

Config returns the Config from the command's context.

func HookCheckIfDatabaseInitialized

func HookCheckIfDatabaseInitialized(cmd *cobra.Command, _ []string) error

HookCheckIfDatabaseInitialized checks if database file exists and is initialized. Returns error if database already exists to prevent accidental re-initialization.

func HookEnsureDatabase

func HookEnsureDatabase(cmd *cobra.Command, args []string) error

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

func HookEnsureGitEnv(cmd *cobra.Command, args []string) error

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

func HookGitSync(cmd *cobra.Command, args []string) error

HookGitSync synchronizes Git repository with current database state.

func HookHelp

func HookHelp(cmd *cobra.Command, _ []string) error

func PrettyVersion

func PrettyVersion(appName, version string) string

PrettyVersion formats version in a pretty way.

Types

type Hook

type Hook func(cmd *cobra.Command, args []string) error

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

func ChainHooks(hooks ...Hook) Hook

ChainHooks chains multiple Hook functions into a single PersistentPreRunE. Hooks run in the order provided. The first non-nil error stops execution.

func HookInjectConfig

func HookInjectConfig(cfg *config.Config) Hook

HookInjectConfig returns a hook that injects the config into the command context.

Jump to

Keyboard shortcuts

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