root

package
v2.57.1 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: MIT Imports: 142 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	HelpLevelAll        = "all"
	HelpLevelLocal      = "local"
	HelpLevelGlobal     = "global"
	HelpLevelCategories = "category"
)

Help levels which can be given to the --help flag, i.e. --help all

Variables

View Source
var HelpCategories = []HelpCategory{
	{Name: "session", Description: "Session and authentication", Flags: []string{"session", "sessionUsername", "sessionPassword", "sessionMode"}},
	{Name: "output", Description: "Output format, filtering and selection", Flags: []string{"output", "outputFile", "outputFileRaw", "outputTemplate", "select", "filter", "view", "compact", "raw", "flatten", "noColor"}},
	{Name: "pagination", Description: "Paging through results", Flags: []string{"pageSize", "currentPage", "totalPages", "includeAll", "withTotalPages", "withTotalElements"}},
	{Name: "http", Description: "HTTP requests (headers, proxy, timeouts and retries)", Flags: []string{"header", "customQueryParam", "noAccept", "proxy", "noProxy", "timeout", "retries", "insecure"}},
	{Name: "cache", Description: "Response caching", Flags: []string{"cache", "noCache", "cacheTTL", "cacheBodyPaths"}},
	{Name: "dry", Description: "Dry run (show requests without sending them)", Flags: []string{"dry", "dryFormat"}},
	{Name: "pipeline", Description: "Piped input, workers and batching", Flags: []string{"nullInput", "allowEmptyPipe", "workers", "maxJobs", "delay", "delayBefore", "abortOnErrors", "progress", "noProgress"}},
	{Name: "confirm", Description: "Confirmation prompts", Flags: []string{"force", "confirm", "confirmText"}},
	{Name: "errors", Description: "Error handling and exit codes", Flags: []string{"withError", "silentStatusCodes", "silentExit"}},
	{Name: "logging", Description: "Logging and the activity log", Flags: []string{"verbose", "debug", "noLog", "logMessage"}},
	{Name: "help", Description: "Help and examples", Flags: []string{"help", "examples"}},
}

HelpCategories are the categories of the global flags (in display order)

View Source
var Logger *logger.Logger

Logger is used to record the log messages which should be visible to the user when using the verbose flag

Functions

func ConvertToCobraCommands added in v2.30.0

func ConvertToCobraCommands(f *cmdutil.Factory, cmd *cobra.Command, extensions []extensions.Extension) error

ConvertToCobraCommands adds the commands provided by the extensions to the given root command. Each extension is added under its own name, and commands from all of the extension's command sources (api specifications, binary and scripts) are merged into a single command tree.

func GetInitLoggerOptions added in v2.52.2

func GetInitLoggerOptions(args []string) logger.Options

GetInitLoggerOptions create a simple logger with a best-guess log level based on the given arguments It will not activate on any environment variables, however it will do a simplistic parsing of the common logging options before the configuration has been read which enables debugging around the configuration and extensions etc.

func HelpLevelNames added in v2.57.0

func HelpLevelNames() []string

HelpLevelNames returns all the valid help levels and categories

func IsExtensionCommand added in v2.57.0

func IsExtensionCommand(cmd *cobra.Command) bool

IsExtensionCommand returns true if the command is provided by an extension

func NormalizeHelpArgs added in v2.57.0

func NormalizeHelpArgs(rootCmd *cobra.Command, args []string) []string

NormalizeHelpArgs supports giving the help level as a separate argument, i.e. "--help local" is converted to "--help=local". The arguments are only changed if the value is a valid help level, and the command is not an extension command (which handles its own help)

func PrepareExtensionArgs added in v2.57.0

func PrepareExtensionArgs(rootCmd *cobra.Command, args []string) []string

PrepareExtensionArgs prepares the arguments of an extension command before it is executed. Extension commands do not parse c8y flags, so:

  • c8y flags before the command (e.g. c8y --session prod.json myext list) are parsed by c8y and removed. They are passed to the extension via the runtime context.
  • for binary commands declared in the extension manifest, the c8y global flags after the command (e.g. myext list --session prod.json --output csv) are also parsed by c8y and removed, the same as for built-in commands. Other arguments are passed to the binary.

The arguments are returned unchanged for all other commands.

func ShouldIgnoreSessionFile added in v2.53.0

func ShouldIgnoreSessionFile(args []string) bool

Types

type CmdRoot

type CmdRoot struct {
	*cobra.Command

	Verbose            bool
	Debug              bool
	ProgressBar        bool
	NoColor            bool
	SessionFile        string
	SessionUsername    string
	SessionPassword    string
	SessionMode        string
	NoLog              bool
	ActivityLogMessage string

	Factory *cmdutil.Factory
	// contains filtered or unexported fields
}

func NewCmdRoot

func NewCmdRoot(f *cmdutil.Factory, version, buildDate string) *CmdRoot

func NewCommand added in v2.52.2

func NewCommand(buildVersion, buildBranch string) (*CmdRoot, error)

Initialize initializes the configuration manager and c8y client

func (*CmdRoot) Configure

func (c *CmdRoot) Configure(disableEncryptionCheck, forceVerbose, forceDebug bool) error

func (*CmdRoot) Execute added in v2.55.0

func (c *CmdRoot) Execute() error

Execute runs the command and flushes any buffered output afterwards (e.g. table output samples multiple rows before resolving the columns)

type HelpCategory added in v2.57.0

type HelpCategory struct {
	Name        string
	Description string
	Flags       []string
}

HelpCategory is a group of global flags which can be shown on its own, i.e. --help output

Jump to

Keyboard shortcuts

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