cmd

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2026 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ExitSuccess indicates clean execution and healthy system status.
	ExitSuccess = 0
	// ExitGeneralError indicates a general runtime failure, critical diagnostic defect, or anomaly.
	ExitGeneralError = 1
	// ExitUsageError indicates invalid CLI arguments, flags, or syntax.
	ExitUsageError = 2
	// ExitConfigError indicates invalid or unparseable configuration settings.
	ExitConfigError = 3
	// ExitAuthError indicates permission denied or authentication failure.
	ExitAuthError = 4
	// ExitNetworkError indicates network unreachable, DNS failure, or remote agent connection error.
	ExitNetworkError = 5
)

Standard CLI Exit Codes

Variables

View Source
var (
	// Version is the current semantic version of Watchdog.
	Version = "1.0.0"
	// GitCommit is the git commit hash injected at build time via ldflags.
	GitCommit = "dev"
	// Commit is maintained for backwards-compatibility with legacy ldflags.
	Commit = "dev"
	// BuildDate is the timestamp when the binary was built.
	BuildDate = "2026-09-23"
	// BuiltBy is the entity or tool that compiled the binary (e.g. goreleaser, docker).
	BuiltBy = ""
)
View Source
var RootCmd = &cobra.Command{
	Use:           "watchdog [command] [flags]",
	Short:         "🐺 Watchdog: Enterprise-Grade System Monitoring & Diagnostics CLI",
	SilenceUsage:  true,
	SilenceErrors: true,
	Long: `Watchdog is a high-performance, cross-platform system monitoring,
automated diagnostics, statistical anomaly detection, SQLite storage engine, and interactive TUI suite.

Key Capabilities:
  - Interactive Terminal Dashboard: Multi-tab real-time CPU/RAM/Disk/Net/Process/Docker TUI.
  - Automated Health Diagnostics: Concurrent heuristic rules with remediation advice.
  - Statistical Anomaly Detection: Real-time Z-score & EWMA anomaly scoring without ML dependencies.
  - Standalone Multi-Format Reports: Rich self-contained HTML (with inline charts), JSON, and CSV.
  - Headless Daemon & Prometheus: Production-ready HTTP REST API and Prometheus metrics exporter.`,
	Example: `  # Launch the interactive real-time terminal UI
  watchdog

  # Run automated health diagnostics and print issues
  watchdog diagnose

  # Generate a standalone HTML health report with charts
  watchdog report -f html -o /tmp/report.html

  # Start the background Prometheus metrics and REST server on port 8443
  watchdog server --port 8443 --token s3cr3t-t0k3n

  # Run with custom configuration and verbose debug logging
  watchdog --config /etc/watchdog.yaml --verbose`,
	PersistentPreRunE: func(cmd *cobra.Command, args []string) error {

		lvl := logger.LevelInfo
		if quiet {
			lvl = logger.LevelError
		} else if verbose {
			lvl = logger.LevelDebug
		}
		log := logger.New(os.Stderr, lvl, jsonLogs, noColor)
		logger.SetDefault(log)

		cfg, path, err := config.Load(cfgFile)
		if err != nil {
			if cfgFile != "" {
				return NewExitError(ExitConfigError, "failed to load specified configuration file %q: %w", cfgFile, err)
			}
			logger.Warnf("Warning loading config: %v; using default settings", err)
			cfg = config.DefaultConfig()
		}
		globalCfg = cfg
		loadedPath = path
		return nil
	},
	RunE: func(cmd *cobra.Command, args []string) error {

		return runDashboard(cmd, args)
	},
}

RootCmd is the base command for Watchdog.

Functions

func Execute

func Execute()

Execute adds all child commands to the root command and sets flags appropriately.

func GetExitCode

func GetExitCode(err error) int

GetExitCode extracts the exit code from an error or returns ExitGeneralError (1) by default. It also intelligently categorizes standard Cobra/pflag CLI usage errors as ExitUsageError (2).

func NewExitError

func NewExitError(code int, format string, a ...interface{}) error

NewExitError constructs an ExitCodeError with a specific exit code and message.

func WrapExitError

func WrapExitError(code int, err error) error

WrapExitError wraps an existing error with a specific exit code.

Types

type ExitCodeError

type ExitCodeError struct {
	Code int
	Err  error
}

ExitCodeError wraps an error with an explicit numeric exit code.

func (*ExitCodeError) Error

func (e *ExitCodeError) Error() string

Error implements the standard error interface.

func (*ExitCodeError) Unwrap

func (e *ExitCodeError) Unwrap() error

Unwrap returns the underlying error.

type VersionInfo

type VersionInfo struct {
	Version   string `json:"version"`
	GitCommit string `json:"git_commit,omitempty"`
	Commit    string `json:"commit"`
	BuildDate string `json:"build_date"`
	BuiltBy   string `json:"built_by,omitempty"`
	GoVersion string `json:"go_version"`
	Platform  string `json:"platform"`
	Compiler  string `json:"compiler"`
}

VersionInfo encapsulates detailed version metadata.

Jump to

Keyboard shortcuts

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