clicobra

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2019 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package clicobra contains helper functionality for applications using Cobra.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Main

func Main(rootCommand *Command, version string)

Main runs the application using the OS runtime and calling os.Exit on the return value of Run.

func Profile

func Profile(
	logger *zap.Logger,
	profilePath string,
	profileType string,
	profileLoops int,
	profileAllowError bool,
	f func() error,
) error

Profile profiles the function.

The function should only return error on system error.

func Run

func Run(rootCommand *Command, version string, runEnv *cli.RunEnv) int

Run runs the application, returning the exit code.

RunEnv will be modified to have dummy values if fields are not set.

Types

type Command

type Command struct {
	// Use is the one-line usage message. Required.
	Use string
	// Short is the short message shown in the 'help' output. Required if Long is set.
	Short string
	// Long is the long message shown in the 'help <this-command>' output. Optional.
	// The Short field will be prepended to the Long field with a newline.
	Long string
	// Args are the expected arguments. Optional.
	Args cobra.PositionalArgs
	// Run is the command to run. Optional.
	Run func(*cli.ExecEnv) error
	// BindFlags allows binding of flags on build. Optional.
	BindFlags func(*pflag.FlagSet)
	// SubCommands are the sub-commands. Optional.
	SubCommands []*Command
}

Command is a command.

type Flags

type Flags struct {
	LogLevel  string
	LogFormat string
	// contains filtered or unexported fields
}

Flags are base flags.

func NewFlags

func NewFlags(devel bool) *Flags

NewFlags returns a new Flags.

Devel should not be set for release binaries.

func (*Flags) BindLogFormat

func (f *Flags) BindLogFormat(flagSet *pflag.FlagSet)

BindLogFormat binds the log-format flag.

func (*Flags) BindLogLevel

func (f *Flags) BindLogLevel(flagSet *pflag.FlagSet)

BindLogLevel binds the log-level flag.

func (*Flags) Devel

func (f *Flags) Devel() bool

Devel returns true if devel is set.

func (*Flags) NewLogger

func (f *Flags) NewLogger(stderr io.Writer) (*zap.Logger, error)

NewLogger creates a new Logger from the Flags.

Jump to

Keyboard shortcuts

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