cli

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2025 License: GPL-3.0, LGPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EXIT_SUCCESS = 0
	EXIT_FAILURE = 1
)

Variables

This section is empty.

Functions

func Execute

func Execute(ctx context.Context, cmd *cobra.Command) int

Execute runs the provided cobra.Command using the given context. Disables the cobra facilities for top-level error reporting. It returns an exit code based on the command execution result:

  • EXIT_SUCCESS if the command executes without error
  • The code from ErrSilentExit if that error is returned
  • EXIT_FAILURE for all other errors, after logging them either with the zap logger from the context or fmt as a fallback

func SignalContext

func SignalContext() context.Context

SignalContext returns a context that is canceled when a termination signal is received. It listens for SIGTERM and SIGINT. On the first signal, the context is canceled with an error describing the signal. If a second signal is received, the process exits immediately. This allows for graceful shutdown on the first signal and forced termination on the second.

Types

type ErrSilentExit

type ErrSilentExit struct {
	Code int // Code is the exit code to be used when exiting.
}

ErrSilentExit represents an error that causes the application to exit silently with a specific exit code.

func (*ErrSilentExit) Error

func (e *ErrSilentExit) Error() string

Error implements the error interface for ErrSilentExit. It returns a formatted string containing the exit code.

Jump to

Keyboard shortcuts

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