Back to

Package cmdutil

Latest Go to latest
Published: Jun 24, 2020 | License: Apache-2.0 | Module:


Package cmdutil provides utility routines for implementing command line tools.


Package Files

func CheckAccess

func CheckAccess(ctx *context.T) (time.Duration, error)

CheckAccess checkes that the current process has credentials that will be valid for at least another 30 minutes. It is intended to allow for more useful and obvious error reporting.

func CreateInfoCommand

func CreateInfoCommand(name, prefix string, info ...func(*context.T, *cmdline.Env, []string) error) *cmdline.Command

CreateInfoCommand creates a command akin to that created by CreatedVersionCommand but also includes the output of running each of the supplied info closures.

func CreateVersionCommand

func CreateVersionCommand(name, prefix string) *cmdline.Command

CreateVersionCommand creates a cmdline 'subcommand' to display version information.

The format of the information printed is:

<prefix>/<version> (<tag1>; <tag2>; ...)

The version and tags are set at build time using something like:

go build -ldflags \
 "-X$version \

func Fatal

func Fatal(args ...interface{})

Fatal mirrors log.Fatal with no prefix and no timestamp.

func Fatalf

func Fatalf(format string, args ...interface{})

Fatalf mirrors log.Fatalf with no prefix and no timestamp.

func RegisterTicketFlags

func RegisterTicketFlags(fs *flag.FlagSet, prefix string, defaultTickets []string, flags *TicketFlags)

RegisterTicketFlags registers the ticket related flags with the supplied FlagSet. The flags are: --<prefix>ticket --<prefix>ticket-timeout --<prefix>ticketrc

func RunnerFuncWithAccessCheck

func RunnerFuncWithAccessCheck(ctxfn func() *context.T, run func(*context.T, *cmdline.Env, []string) error) cmdline.Runner

RunnerFuncWithAccessCheck is like V23RunnerFunc, but also calls CheckAccess to test for credential existence/expiry.

func V23RunnerFunc

func V23RunnerFunc(ctxfn func() *context.T, run func(*context.T, *cmdline.Env, []string) error) cmdline.Runner

V23RunnerFunc is like cmdutil.RunnerFunc, but allows for a context.T parameter that is given the context as obtained from ctxfn.

func WriteBlessings

func WriteBlessings(ctx *context.T, out io.Writer)

WriteBlessings will write the current principal and blessings to the supplied io.Writer.

func WriteWrappedMessage

func WriteWrappedMessage(w io.Writer, m string)

WriteWrappedMessage writes the message to the specified io.Writer taking care to line wrap it appropriately for the terminal width.

type NetworkAddressFlag

type NetworkAddressFlag struct {
	Address   string
	Host      string
	Port      string
	Specified bool

NetworkAddressFlag represents a network address in host:port format.

func (*NetworkAddressFlag) Get

func (na *NetworkAddressFlag) Get() interface{}

Get implements flag.Value.Get

func (*NetworkAddressFlag) Set

func (na *NetworkAddressFlag) Set(v string) error

Set implements flag.Value.Set

func (*NetworkAddressFlag) String

func (na *NetworkAddressFlag) String() string

String implements flag.Value.String

type RunnerFunc

type RunnerFunc func(*cmdline.Env, []string) error

RunnerFunc is an adapter that turns regular functions into cmdline.Runners.

func (RunnerFunc) Run

func (f RunnerFunc) Run(env *cmdline.Env, args []string) error

Run implements the cmdline.Runner interface method by calling f(env, args) and also ensures that vlog logging is configured and that a flush is done at the end.

type TicketFlags

type TicketFlags struct {
	Tickets      []string
	TicketRCFile string

	Timeout time.Duration
	// contains filtered or unexported fields

TicketFlags represents an implementation of flag.Value that can be used to specify tickets either in comma separated form or by repeating the same flag. That is, either:



--flag=t1 --flag=t2 --flag=t3


--flag=t1,t2 --flag=t3

func (*TicketFlags) ReadEnvOrFile

func (tf *TicketFlags) ReadEnvOrFile() error

ReadEnvOrFile will attempt to obtain values for the tickets to use from the environment or from a file if none have been explicitly set on the command line. If no flags were specified it will read the environment variable GRAIL_TICKETS and if that's empty it will attempt to read the file specified by the ticketrc flag (or it's default value).

func (*TicketFlags) Set

func (tf *TicketFlags) Set(v string) error

Set implements flag.Value.

func (*TicketFlags) String

func (tf *TicketFlags) String() string

String implements flag.Value.

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier