Documentation ¶
Overview ¶
Package common provides some helper functionality for building command line handlers.
Index ¶
- Constants
- func AddCommonFlags(c *cobra.Command)
- func ArgsWithHelp(argFns ...cobra.PositionalArgs) cobra.PositionalArgs
- func ContextWithTimeout() (context.Context, context.CancelFunc)
- func FormatExpiration(delta time.Duration) string
- func FormatTime(moment time.Time) string
- func GetGRPCConnection() (*grpc.ClientConn, context.Context, func(), error)
- func MustBool(flags *pflag.FlagSet, name string) bool
- func WithGRPCHandler(handler GRPCHandler) func(cmd *cobra.Command, args []string) error
- type GRPCHandler
- type PrettyPrinter
Constants ¶
const ( // TokenEnvVarName is the environment variable name used to pass a service // account token. TokenEnvVarName = "INFRA_TOKEN" )
Variables ¶
This section is empty.
Functions ¶
func AddCommonFlags ¶
AddCommonFlags adds connection-related flags to infractl.
func ArgsWithHelp ¶
func ArgsWithHelp(argFns ...cobra.PositionalArgs) cobra.PositionalArgs
ArgsWithHelp composes a series of positional argument check functions, and if any of them fail it will print the current command's help message.
func ContextWithTimeout ¶
func ContextWithTimeout() (context.Context, context.CancelFunc)
ContextWithTimeout returns a context and a cancel function that is bound to the given --timeout flag value.
func FormatExpiration ¶
FormatExpiration formats the given duration in a human-friendly way, indicating how long in the future the event will happen.
func FormatTime ¶
FormatTime formats the given time in a human-friendly way, indicating how long in the past the event happened.
func GetGRPCConnection ¶
func GetGRPCConnection() (*grpc.ClientConn, context.Context, func(), error)
GetGRPCConnection gets a grpc connection to the infra-server with the correct auth.
func MustBool ¶
MustBool looks up the named bool flag in the given flag set and panics if an error is returned.
func WithGRPCHandler ¶
func WithGRPCHandler(handler GRPCHandler) func(cmd *cobra.Command, args []string) error
WithGRPCHandler performs all of the gRPC connection setup and teardown, as well as rendering the returned type as either JSON or in a human-readable fashion.
Types ¶
type GRPCHandler ¶
type GRPCHandler func(ctx context.Context, conn *grpc.ClientConn, cmd *cobra.Command, args []string) (PrettyPrinter, error)
GRPCHandler represents a function that consumes a gRPC connection, and produces a pretty-printable type.
type PrettyPrinter ¶
type PrettyPrinter interface { // PrettyPrint renders this type in a pretty, human-readable fashion to // STDOUT. PrettyPrint(cmd *cobra.Command) PrettyJSONPrint(cmd *cobra.Command) error }
PrettyPrinter represents a type that knows how to render itself in a pretty, human-readable fashion to STDOUT.