...

Package cmdx

import "github.com/ory/x/cmdx"
Overview
Index

Overview ▾

Index ▾

Constants
Variables
func AskForConfirmation(s string, stdin io.Reader, stdout io.Writer) bool
func CheckResponse(err error, expectedStatusCode int, response *http.Response)
func EnvVarExamplesHelpMessage(name string) string
func ExactArgs(cmd *cobra.Command, args []string, l int)
func Exec(t testing.TB, cmd *cobra.Command, stdIn io.Reader, args ...string) (string, string, error)
func ExecCtx(ctx context.Context, cmd *cobra.Command, stdIn io.Reader, args ...string) (string, string, error)
func ExecExpectedErr(t testing.TB, cmd *cobra.Command, args ...string) string
func ExecExpectedErrCtx(ctx context.Context, t require.TestingT, cmd *cobra.Command, args ...string) string
func ExecNoErr(t testing.TB, cmd *cobra.Command, args ...string) string
func ExecNoErrCtx(ctx context.Context, t require.TestingT, cmd *cobra.Command, args ...string) string
func ExpectDependency(logger *logrusx.Logger, dependencies ...interface{})
func FailSilently(cmd *cobra.Command) error
func Fatalf(message string, args ...interface{})
func FormatResponse(o interface{}) string
func MinArgs(cmd *cobra.Command, args []string, min int)
func Must(err error, message string, args ...interface{})
func PrintErrors(cmd *cobra.Command, errs map[string]error)
func PrintJSONAble(cmd *cobra.Command, d interface{String() string})
func PrintRow(cmd *cobra.Command, row TableRow)
func PrintTable(cmd *cobra.Command, table Table)
func RangeArgs(cmd *cobra.Command, args []string, r []int)
func RegisterFormatFlags(flags *pflag.FlagSet)
func RegisterJSONFormatFlags(flags *pflag.FlagSet)
func RegisterNoiseFlags(flags *pflag.FlagSet)
func Version(gitTag, gitHash, buildTime *string) *cobra.Command
type CommandExecuter
    func (c *CommandExecuter) Exec(stdin io.Reader, args ...string) (string, string, error)
    func (c *CommandExecuter) ExecExpectedErr(t require.TestingT, args ...string) string
    func (c *CommandExecuter) ExecNoErr(t require.TestingT, args ...string) string
type ConditionalPrinter
    func NewConditionalPrinter(w io.Writer, print bool) *ConditionalPrinter
    func NewLoudErrPrinter(cmd *cobra.Command) *ConditionalPrinter
    func NewLoudOutPrinter(cmd *cobra.Command) *ConditionalPrinter
    func NewLoudPrinter(cmd *cobra.Command, w io.Writer) *ConditionalPrinter
    func NewQuietErrPrinter(cmd *cobra.Command) *ConditionalPrinter
    func NewQuietOutPrinter(cmd *cobra.Command) *ConditionalPrinter
    func NewQuietPrinter(cmd *cobra.Command, w io.Writer) *ConditionalPrinter
    func (p *ConditionalPrinter) Print(a ...interface{}) (n int, err error)
    func (p *ConditionalPrinter) Printf(format string, a ...interface{}) (n int, err error)
    func (p *ConditionalPrinter) Println(a ...interface{}) (n int, err error)
type Table
type TableHeader
type TableRow

Package files

args.go env.go helper.go noise_printer.go printing.go user_input.go version.go

Constants

const (
    FormatQuiet      format = "quiet"
    FormatTable      format = "table"
    FormatJSON       format = "json"
    FormatJSONPretty format = "json-pretty"
    FormatDefault    format = "default"

    FlagFormat = "format"

    None = "<none>"
)
const (
    FlagQuiet = "quiet"
)

Variables

var (
    // ErrNilDependency is returned if a dependency is missing.
    ErrNilDependency = errors.New("a dependency was expected to be defined but is nil. Please open an issue with the stack trace")
    // ErrNoPrintButFail is returned to detect a failure state that was already reported to the user in some way
    ErrNoPrintButFail = errors.New("this error should never be printed")
)

func AskForConfirmation

func AskForConfirmation(s string, stdin io.Reader, stdout io.Writer) bool

asks for confirmation with the question string s and reads the answer pass nil to use os.Stdin and os.Stdout

func CheckResponse

func CheckResponse(err error, expectedStatusCode int, response *http.Response)

CheckResponse fatals if err is nil or the response.StatusCode does not match the expectedStatusCode

func EnvVarExamplesHelpMessage

func EnvVarExamplesHelpMessage(name string) string

EnvVarExamplesHelpMessage returns a string containing documentation on how to use environment variables.

func ExactArgs

func ExactArgs(cmd *cobra.Command, args []string, l int)

ExactArgs fatals if args does not equal l.

func Exec

func Exec(t testing.TB, cmd *cobra.Command, stdIn io.Reader, args ...string) (string, string, error)

Exec runs the provided cobra command with the given reader as STD_IN and the given args. Returns STD_OUT, STD_ERR and the error from the execution.

func ExecCtx

func ExecCtx(ctx context.Context, cmd *cobra.Command, stdIn io.Reader, args ...string) (string, string, error)

func ExecExpectedErr

func ExecExpectedErr(t testing.TB, cmd *cobra.Command, args ...string) string

ExecExpectedErr is a helper that assumes a failing run from Exec returning ErrNoPrintButFail Returns STD_ERR.

func ExecExpectedErrCtx

func ExecExpectedErrCtx(ctx context.Context, t require.TestingT, cmd *cobra.Command, args ...string) string

func ExecNoErr

func ExecNoErr(t testing.TB, cmd *cobra.Command, args ...string) string

ExecNoErr is a helper that assumes a successful run from Exec. Returns STD_OUT.

func ExecNoErrCtx

func ExecNoErrCtx(ctx context.Context, t require.TestingT, cmd *cobra.Command, args ...string) string

func ExpectDependency

func ExpectDependency(logger *logrusx.Logger, dependencies ...interface{})

ExpectDependency expects every dependency to be not nil or it fatals.

func FailSilently

func FailSilently(cmd *cobra.Command) error

FailSilently is supposed to be used within a commands RunE function. It silences cobras error handling and returns the ErrNoPrintButFail error.

func Fatalf

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

Fatalf prints to os.Stderr and exists with code 1.

func FormatResponse

func FormatResponse(o interface{}) string

FormatResponse takes an object and prints a json.MarshalIdent version of it or fatals.

func MinArgs

func MinArgs(cmd *cobra.Command, args []string, min int)

MinArgs fatals if args does not satisfy min.

func Must

func Must(err error, message string, args ...interface{})

Must fatals with the optional message if err is not nil.

func PrintErrors

func PrintErrors(cmd *cobra.Command, errs map[string]error)

func PrintJSONAble

func PrintJSONAble(cmd *cobra.Command, d interface{ String() string })

func PrintRow

func PrintRow(cmd *cobra.Command, row TableRow)

func PrintTable

func PrintTable(cmd *cobra.Command, table Table)

func RangeArgs

func RangeArgs(cmd *cobra.Command, args []string, r []int)

RangeArgs fatals if args does not satisfy any of the lengths set in r.

func RegisterFormatFlags

func RegisterFormatFlags(flags *pflag.FlagSet)

func RegisterJSONFormatFlags

func RegisterJSONFormatFlags(flags *pflag.FlagSet)

func RegisterNoiseFlags

func RegisterNoiseFlags(flags *pflag.FlagSet)

func Version

func Version(gitTag, gitHash, buildTime *string) *cobra.Command

Version returns a *cobra.Command that handles the `version` command.

type CommandExecuter

type CommandExecuter struct {
    New            func() *cobra.Command
    Ctx            context.Context
    PersistentArgs []string
}

func (*CommandExecuter) Exec

func (c *CommandExecuter) Exec(stdin io.Reader, args ...string) (string, string, error)

func (*CommandExecuter) ExecExpectedErr

func (c *CommandExecuter) ExecExpectedErr(t require.TestingT, args ...string) string

func (*CommandExecuter) ExecNoErr

func (c *CommandExecuter) ExecNoErr(t require.TestingT, args ...string) string

type ConditionalPrinter

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

func NewConditionalPrinter

func NewConditionalPrinter(w io.Writer, print bool) *ConditionalPrinter

func NewLoudErrPrinter

func NewLoudErrPrinter(cmd *cobra.Command) *ConditionalPrinter

NewLoudErrPrinter returns a ConditionalPrinter that only prints to cmd.ErrOrStderr when --quiet is not set

func NewLoudOutPrinter

func NewLoudOutPrinter(cmd *cobra.Command) *ConditionalPrinter

NewLoudOutPrinter returns a ConditionalPrinter that only prints to cmd.OutOrStdout when --quiet is not set

func NewLoudPrinter

func NewLoudPrinter(cmd *cobra.Command, w io.Writer) *ConditionalPrinter

NewLoudPrinter returns a ConditionalPrinter that only prints to w when --quiet is not set

func NewQuietErrPrinter

func NewQuietErrPrinter(cmd *cobra.Command) *ConditionalPrinter

NewQuietErrPrinter returns a ConditionalPrinter that only prints to cmd.ErrOrStderr when --quiet is set

func NewQuietOutPrinter

func NewQuietOutPrinter(cmd *cobra.Command) *ConditionalPrinter

NewQuietOutPrinter returns a ConditionalPrinter that only prints to cmd.OutOrStdout when --quiet is set

func NewQuietPrinter

func NewQuietPrinter(cmd *cobra.Command, w io.Writer) *ConditionalPrinter

NewQuietPrinter returns a ConditionalPrinter that only prints to w when --quiet is set

func (*ConditionalPrinter) Print

func (p *ConditionalPrinter) Print(a ...interface{}) (n int, err error)

func (*ConditionalPrinter) Printf

func (p *ConditionalPrinter) Printf(format string, a ...interface{}) (n int, err error)

func (*ConditionalPrinter) Println

func (p *ConditionalPrinter) Println(a ...interface{}) (n int, err error)

type Table

type Table interface {
    TableHeader
    Table() [][]string
    Interface() interface{}
    Len() int
}

type TableHeader

type TableHeader interface {
    Header() []string
}

type TableRow

type TableRow interface {
    TableHeader
    Columns() []string
    Interface() interface{}
}