cli

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2022 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Copyright © 2021 Optable Technologies Inc. All rights reserved. See LICENSE for details.

Copyright © 2021 Optable Technologies Inc. All rights reserved. See LICENSE for details.

Copyright © 2021 Optable Technologies Inc. All rights reserved. See LICENSE for details.

Index

Constants

This section is empty.

Variables

View Source
var JSONLoader = &jsonLoader{}

Functions

func LevelFromVerbosity

func LevelFromVerbosity(v int) zerolog.Level

LevelFromVerbosity takes a command-line `-v` stackable flag count, e.g. `-vv`, `-vvv` and transforms it into a sensible loglevel. The mapping is:

``:     Warn
`-v`:   Info
`-vv`:  Debug
`-vvv`: Trace

func NewLogger

func NewLogger(cliName string, verbosity int) *zerolog.Logger

Types

type ConfigDir added in v0.2.0

type ConfigDir struct {
	// contains filtered or unexported fields
}

ConfigDir allows managing a multiple contextual configuration files. Each configuration is given a context name, e.g. `prod`, `staging`, `devel` and each stores a specific configuration.

func NewConfigDir added in v0.2.0

func NewConfigDir(path string, opts ...ConfigDirOption) (*ConfigDir, error)

NewConfigDir creates a ConfigDir at a given path.

func (*ConfigDir) Current added in v0.2.0

func (c *ConfigDir) Current(as interface{}) (*configInfo, error)

func (*ConfigDir) Get added in v0.2.0

func (c *ConfigDir) Get(name string, as interface{}) error

func (*ConfigDir) List added in v0.2.0

func (c *ConfigDir) List() ([]string, error)

func (*ConfigDir) Set added in v0.2.0

func (c *ConfigDir) Set(name string, from interface{}) error

func (*ConfigDir) Use added in v0.2.0

func (c *ConfigDir) Use(name string) error

type ConfigDirCli added in v0.2.0

type ConfigDirCli struct {
	ConfigDirFlag
	Config ConfigDirCmd `cmd:"config"`
	// contains filtered or unexported fields
}

func (*ConfigDirCli) Get added in v0.2.0

func (c *ConfigDirCli) Get(cfg interface{}) error

func (*ConfigDirCli) KongInit added in v0.2.0

func (c *ConfigDirCli) KongInit(path string, options ...ConfigDirOption) kong.Option

func (*ConfigDirCli) Set added in v0.2.0

func (c *ConfigDirCli) Set(cfg interface{}, setCurrent bool) error

type ConfigDirCmd added in v0.2.0

type ConfigDirCmd struct {
	Use  ConfigUseCmd  `cmd:"use"`
	List ConfigListCmd `cmd:"list"`
}

func (*ConfigDirCmd) BeforeResolve added in v0.2.0

func (u *ConfigDirCmd) BeforeResolve(c *ConfigDirCli) (err error)

func (*ConfigDirCmd) Help added in v0.2.0

func (u *ConfigDirCmd) Help() string

type ConfigDirFlag added in v0.2.0

type ConfigDirFlag struct {
	Config string `opt:""`
}

func (*ConfigDirFlag) BeforeResolve added in v0.2.0

func (f *ConfigDirFlag) BeforeResolve(c *ConfigDirCli) (err error)

func (*ConfigDirFlag) Help added in v0.2.0

func (f *ConfigDirFlag) Help() string

type ConfigDirOption added in v0.2.0

type ConfigDirOption interface {
	// contains filtered or unexported methods
}

func WithConfigDirLoader added in v0.2.0

func WithConfigDirLoader(loader ConfigLoader) ConfigDirOption

func WithXdgConfigPath added in v0.2.0

func WithXdgConfigPath(configPath string) ConfigDirOption

type ConfigListCmd added in v0.2.0

type ConfigListCmd struct {
}

func (*ConfigListCmd) BeforeResolve added in v0.2.0

func (u *ConfigListCmd) BeforeResolve(c *ConfigDirCli) (err error)

func (*ConfigListCmd) Run added in v0.2.0

func (u *ConfigListCmd) Run(c *ConfigDirCli) error

type ConfigLoader added in v0.2.0

type ConfigLoader interface {
	Unmarshal([]byte, interface{}) error
	Marshal(interface{}) ([]byte, error)
}

type ConfigUseCmd added in v0.2.0

type ConfigUseCmd struct {
	Name string `arg:"" placeholder:"<name>"`
}

func (*ConfigUseCmd) BeforeResolve added in v0.2.0

func (u *ConfigUseCmd) BeforeResolve(c *ConfigDirCli) (err error)

func (*ConfigUseCmd) Run added in v0.2.0

func (u *ConfigUseCmd) Run(c *ConfigDirCli) error

type ProfilingFlag added in v0.2.0

type ProfilingFlag struct {
	Profiling string `opt:"" hidden:"true" default:""`
}

Profiling is a struct that can be embedded in any kong cli to enable easy and convenient profiling for performance analysis. The flag is hidden from the help message such that we can use it in public cli.

The supported values are:

  • "cpu": Enables CPU profiling.
  • "memory": Enables heap memory profiling.
  • "block": Enables block (contention) profiling.
  • "mutex": Enables mutex profiling.
  • "trace": Enables trace profiling.

The profiling file path will be shown to stderr and can be opened with `go tool pprof $file` or `go tool pprof -http localhost:8080 $file`

In order to enable profiling, one should use the command like this: ``` stopProfiling := cli.Profiling.Start() defer stopProfiling() ```

func (*ProfilingFlag) Start added in v0.2.0

func (p *ProfilingFlag) Start() func()

Start starts the profiling operation. It returns a function that needs to be called when the profiling should stop.

Jump to

Keyboard shortcuts

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