Documentation
¶
Index ¶
- Constants
- Variables
- func ConvertToCobraCommands(f *cmdutil.Factory, cmd *cobra.Command, extensions []extensions.Extension) error
- func GetInitLoggerOptions(args []string) logger.Options
- func HelpLevelNames() []string
- func IsExtensionCommand(cmd *cobra.Command) bool
- func NormalizeHelpArgs(rootCmd *cobra.Command, args []string) []string
- func PrepareExtensionArgs(rootCmd *cobra.Command, args []string) []string
- func ShouldIgnoreSessionFile(args []string) bool
- type CmdRoot
- type HelpCategory
Constants ¶
const ( HelpLevelAll = "all" HelpLevelLocal = "local" HelpLevelGlobal = "global" HelpLevelCategories = "category" )
Help levels which can be given to the --help flag, i.e. --help all
Variables ¶
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)
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
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
IsExtensionCommand returns true if the command is provided by an extension
func NormalizeHelpArgs ¶ added in v2.57.0
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
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
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 NewCommand ¶ added in v2.52.2
Initialize initializes the configuration manager and c8y client
type HelpCategory ¶ added in v2.57.0
HelpCategory is a group of global flags which can be shown on its own, i.e. --help output