cmd

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2025 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Overview

Package cmd provides a common utilities and helper function to standarise the way omni apps use cobra and viper to produce consistent cli experience for both users and devs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BindHomeFlag

func BindHomeFlag(flags *pflag.FlagSet, homeDir *string)

BindHomeFlag binds the home flag to the given flag set. This is generally only required for apps that require multiple config files or persist data to disk. Using this flag will result in the viper config directory to be updated from default "." to "<home>/config".

func LogFlags

func LogFlags(ctx context.Context, flags *pflag.FlagSet) error

LogFlags logs the configured flags kv pairs.

func Main

func Main(cmd *cobra.Command)

Main is the main entry point for the omni application binaries. Usage:

   func main() {
	     libcmd.Main(appcmd.New())
   }

func NewRootCmd

func NewRootCmd(appName string, appDescription string, subCmds ...*cobra.Command) *cobra.Command

NewRootCmd returns a new root cobra command that handles our command line tool. It sets up the general viper config and binds the cobra flags to the viper flags.

func Redact added in v0.10.0

func Redact(flag, val string) string

Redact returns a redacted version of the given flag value. It currently supports redacting passwords in valid URLs as well as flags that contains words like "token", "password", "secret", "db" or "key".

func SilenceErrUsage

func SilenceErrUsage(cmd *cobra.Command)

SilenceErrUsage silences the usage and error printing.

func WrapRunE added in v0.10.0

func WrapRunE(cmd *cobra.Command, printFatal func(ctx context.Context, err error))

WrapRunE wraps all (nested) RunE functions adding omni logging (stack traces + structured errors). Done here, so cobra command/flag errors are cli style (usage + simple errors).

Types

This section is empty.

Jump to

Keyboard shortcuts

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