base: github.com/grailbio/base/cmdutil Index | Files | Directories

package cmdutil

import "github.com/grailbio/base/cmdutil"

Package cmdutil provides utility routines for implementing command line tools.

Index

Package Files

access.go logging.go network_flags.go output.go runner.go ticket_flags.go version.go

func CheckAccess Uses

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 Uses

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 Uses

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 github.com/grailbio/base/cmdutil.version=$version \
  -X github.com/grailbio/base/cmdutil.tags=$tags"

func Fatal Uses

func Fatal(args ...interface{})

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

func Fatalf Uses

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

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

func RegisterTicketFlags Uses

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 Uses

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 Uses

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 Uses

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

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

func WriteWrappedMessage Uses

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 Uses

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

NetworkAddressFlag represents a network address in host:port format.

func (*NetworkAddressFlag) Get Uses

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

Get implements flag.Value.Get

func (*NetworkAddressFlag) Set Uses

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

Set implements flag.Value.Set

func (*NetworkAddressFlag) String Uses

func (na *NetworkAddressFlag) String() string

String implements flag.Value.String

type RunnerFunc Uses

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

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

func (RunnerFunc) Run Uses

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 Uses

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,t2,t3

and/or

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

and/or

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

func (*TicketFlags) ReadEnvOrFile Uses

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 Uses

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

Set implements flag.Value.

func (*TicketFlags) String Uses

func (tf *TicketFlags) String() string

String implements flag.Value.

Directories

PathSynopsis
cmdline-test
interactivePackage interactive is switching defaults for logging to not output anything to stderr.
naked-test

Package cmdutil imports 19 packages (graph) and is imported by 3 packages. Updated 2019-11-10. Refresh now. Tools for package owners.