cli

package
v0.0.0-...-40cbffd Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2026 License: Apache-2.0 Imports: 92 Imported by: 0

Documentation

Overview

Package cli defines the Cobra command surface for the divekit tool

Index

Constants

View Source
const (
	MsgConflictingFlags        = "Conflicting options specified"
	MsgNoDistributionsFound    = "No distributions found in this directory"
	MsgDistributionNotFound    = "Distribution not found"
	MsgHandlerCreationFailed   = "Could not initialize command"
	MsgHandlerSetupFailed      = "Setup failed"
	MsgHandlerValidationFailed = "Configuration is invalid"
	MsgProposalFailed          = "Could not prepare changes"
	MsgExecutionFailed         = "Command execution failed"
)

User-friendly error messages

Variables

View Source
var (
	// LogLevelFlag mirrors the parsed root log level for legacy command code.
	LogLevelFlag = defaultRootLogLevel
	// NonInteractiveFlag mirrors parsed non-interactive mode for legacy command code.
	NonInteractiveFlag bool
	// AssumeYesFlag mirrors parsed assume-yes mode for legacy command code.
	AssumeYesFlag bool
	// NoIndexFlag mirrors parsed index opt-out for legacy command code.
	NoIndexFlag bool
)
View Source
var (
	// IndexCmd represents the base command for all index operations.
	IndexCmd = &cobra.Command{
		Use:   "index",
		Short: "Manage the Divekit project index",
		Long: `Manage the local project index for fast project discovery and search.

The project index is a local database that tracks Divekit projects and their
distributions. It enables fast searching and navigation between projects.

SUBCOMMANDS:
  add       Add projects to the index
  refresh   Verify and update all indexed projects`,
		Example: `  # Add current directory to index
  divekit index add

  # Add a specific project
  divekit index add /path/to/project

  # Recursively find and add all projects
  divekit index add --recursive

  # Find sibling projects (go up one dir, scan siblings)
  divekit index add --siblings

  # Refresh the entire index (verify paths, update distributions)
  divekit index refresh`,
	}
)

Functions

func Execute

func Execute() error

Execute runs the root command and handles any errors that occur during execution. This is the main entry point called from main() and will start the cobra command parsing and execution process.

func NewRootCmd

func NewRootCmd() *cobra.Command

NewRootCmd creates and returns the root command for the divekit CLI application. This command serves as the entry point for all divekit operations including repository initialization, distribution, patching, and management.

func RegisterGUIRuntime

func RegisterGUIRuntime(run guiRuntimeFunc)

RegisterGUIRuntime installs the GUI runtime implementation for executable builds. Consumer tools such as doc generators can import internal/cli without linking the GUI runtime.

func SetCmdFlags

func SetCmdFlags(cmd *cobra.Command)

SetCmdFlags configures the persistent flags for the given cobra command. It sets up global flags including log level and non-interactive mode that apply to all subcommands in the divekit CLI.

func WaitForBackgroundTasks

func WaitForBackgroundTasks(timeout time.Duration)

WaitForBackgroundTasks waits for all background goroutines to complete with the specified timeout. If the timeout is reached, it logs a warning and returns without waiting further.

Types

type CommandError

type CommandError struct {
	apperror.Carrier
	ErrorType ErrorType
	Message   string
	Err       error         // Wrapped error
	Context   *ErrorContext // Optional additional context
}

CommandError represents a specific error in the internal/cli package

func NewCommandError

func NewCommandError(errorType ErrorType, message string, err error) *CommandError

NewCommandError creates a new CommandError

func NewConflictingFlagsError

func NewConflictingFlagsError(details string) *CommandError

NewConflictingFlagsError creates a new conflicting flags error

func NewDistributionNotFoundError

func NewDistributionNotFoundError(distributionName string) *CommandError

NewDistributionNotFoundError creates a new distribution not found error

func NewExecutionFailedError

func NewExecutionFailedError(operation string, err error) *CommandError

NewExecutionFailedError creates a new execution failed error

func NewHandlerCreationFailedError

func NewHandlerCreationFailedError(handlerType string, err error) *CommandError

NewHandlerCreationFailedError creates a new handler creation failed error

func NewHandlerSetupFailedError

func NewHandlerSetupFailedError(err error) *CommandError

NewHandlerSetupFailedError creates a new handler setup failed error

func NewHandlerValidationFailedError

func NewHandlerValidationFailedError(err error) *CommandError

NewHandlerValidationFailedError creates a new handler validation failed error

func NewHomeInitError

func NewHomeInitError(err error) *CommandError

NewHomeInitError creates a new error for divekit home directory initialization failures

func NewLogLevelDefinitionError

func NewLogLevelDefinitionError(err error) *CommandError

NewLogLevelDefinitionError creates a new error for logging level definition failures

func NewMembersExecutionFailedError

func NewMembersExecutionFailedError(operation string, err error) *CommandError

NewMembersExecutionFailedError creates a members-specific execution error.

func NewNoDistributionsFoundError

func NewNoDistributionsFoundError(workingDir string) *CommandError

NewNoDistributionsFoundError creates a new no distributions found error

func NewProposalFailedError

func NewProposalFailedError(err error) *CommandError

NewProposalFailedError creates a new proposal failed error

func (*CommandError) Error

func (e *CommandError) Error() string

Error implements the error interface

func (*CommandError) Unwrap

func (e *CommandError) Unwrap() error

Unwrap returns the wrapped cause for errors.Is/As support

func (*CommandError) WithContext

func (e *CommandError) WithContext(ctx ErrorContext) *CommandError

WithContext adds context to the error and returns a new CommandError

type ErrorContext

type ErrorContext struct {
	Operation string
	Resource  string
	UserID    string
}

ErrorContext provides additional context for errors

type ErrorType

type ErrorType int

ErrorType defines the different types of errors in the internal/cli package

const (
	ErrConflictingFlags ErrorType = iota
	ErrNoDistributionsFound
	ErrDistributionNotFound
	ErrHandlerCreationFailed
	ErrHandlerSetupFailed
	ErrHandlerValidationFailed
	ErrProposalFailed
	ErrExecutionFailed
)

Define error types as constants

type GUIRuntimeNotLinkedError

type GUIRuntimeNotLinkedError struct{}

GUIRuntimeNotLinkedError indicates that the GUI command was built without its runtime implementation.

func (*GUIRuntimeNotLinkedError) Error

func (e *GUIRuntimeNotLinkedError) Error() string

Error implements the error interface.

type InvalidArgsError

type InvalidArgsError struct {
	Msg string
}

InvalidArgsError represents an error that occurs when invalid arguments are provided to a divekit command. It wraps the error message for consistent error handling across the CLI.

func (*InvalidArgsError) Category

func (e *InvalidArgsError) Category() apperror.Category

Category classifies invalid CLI arguments as user-correctable validation errors.

func (*InvalidArgsError) Cause

func (e *InvalidArgsError) Cause() error

Cause returns the underlying error cause.

func (*InvalidArgsError) Details

func (e *InvalidArgsError) Details() map[string]any

Details returns structured error metadata.

func (*InvalidArgsError) Error

func (e *InvalidArgsError) Error() string

Error returns the error message associated with the InvalidArgsError.

func (*InvalidArgsError) ExitCode

func (e *InvalidArgsError) ExitCode() int

ExitCode returns the standard validation failure exit code.

func (*InvalidArgsError) IsCritical

func (e *InvalidArgsError) IsCritical() bool

IsCritical reports whether this error should stop command execution.

func (*InvalidArgsError) Retryable

func (e *InvalidArgsError) Retryable() bool

Retryable reports whether retrying without changing input is useful.

func (*InvalidArgsError) UserMessage

func (e *InvalidArgsError) UserMessage() string

UserMessage returns the message shown to CLI users.

Source Files

Jump to

Keyboard shortcuts

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