Documentation
¶
Index ¶
- func ContainsAny(str string, substrings ...string) bool
- func ExecuteCommand(ctx context.Context, cmd CmdOptions, args ...string) error
- func MarkAllFlagsHidden(target *cobra.Command, excluded ...string)
- func MarkFlagsHidden(target *cobra.Command, hidden ...string)
- func NewMockFileInfo(name string, size int64, mode os.FileMode, isDir bool, t time.Time) os.FileInfo
- func NewTestIOStreams(r *TestFdReader) (iostream *IOStreams, in *TestFdReader, out *bytes.Buffer, errOut *bytes.Buffer)
- func ParseLevel(s string) (slog.Level, error)
- func RejectDisallowedFlags(cmd *cobra.Command, disallowed ...string) error
- func RemoveLinesContaining(s string, substrings ...string) string
- type BaseOptions
- type CmdOptions
- type FdReader
- type IOStreams
- func (io *IOStreams) Debugf(format string, args ...any)
- func (io *IOStreams) Errorf(format string, args ...any)
- func (io *IOStreams) Infof(format string, args ...any)
- func (io *IOStreams) Print(s string)
- func (io *IOStreams) Printf(format string, args ...any)
- func (io *IOStreams) SetLevel(l slog.Level)
- func (io *IOStreams) Warnf(format string, args ...any)
- type StdioOption
- type StdioOptions
- type TestFdReader
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ContainsAny ¶
ContainsAny reports whether str contains any of substrings.
func ExecuteCommand ¶
func ExecuteCommand(ctx context.Context, cmd CmdOptions, args ...string) error
ExecuteCommand executes the provided command options by first completing, then validating, and finally running the command.
func MarkAllFlagsHidden ¶
MarkAllFlagsHidden hides all flags from the target's help output.
func MarkFlagsHidden ¶
MarkFlagsHidden hides the given flags from the target's help output.
func NewMockFileInfo ¶
func NewTestIOStreams ¶
func NewTestIOStreams(r *TestFdReader) (iostream *IOStreams, in *TestFdReader, out *bytes.Buffer, errOut *bytes.Buffer)
NewTestIOStreamsWithMockInput returns IOStreams with mock input, a TestFdReader and out and error buffers for unit tests.
func RejectDisallowedFlags ¶
func RemoveLinesContaining ¶
RemoveLinesContaining removes any lines that contain any of substrings.
Types ¶
type BaseOptions ¶
type BaseOptions interface {
Complete() error // Complete prepares the options for the command by setting required values.
Validate() error // Validate checks that the options are valid before running the command.
}
BaseOptions defines the interface for shared setup and validation logic.
type CmdOptions ¶
type CmdOptions interface {
BaseOptions
Run(ctx context.Context, args ...string) error
}
CmdOptions includes BaseOptions and adds the ability to run the command logic.
type FdReader ¶
FdReader defines the interface for file-like objects that can be read from, provide a file descriptor, and return file information.
type IOStreams ¶
type IOStreams struct {
In FdReader
Out io.Writer
ErrOut io.Writer
// contains filtered or unexported fields
}
func NewDefaultIOStreams ¶
func NewDefaultIOStreams() *IOStreams
NewDefaultIOStreams returns the default IOStreams (using os.Stdin, os.Stdout, os.Stderr).
func NewTestIOStreamsDiscard ¶
func NewTestIOStreamsDiscard(in *TestFdReader) *IOStreams
NewTestIOStreamsDiscard returns IOStreams with mocked input, and discards both output and error output.
func (*IOStreams) Debugf ¶
Debugf writes formatted debug output to the error stream. if Verbose is enabled.
type StdioOption ¶
type StdioOption func(*StdioOptions)
func WithErr ¶
func WithErr(w io.Writer) StdioOption
func WithIn ¶
func WithIn(r FdReader) StdioOption
func WithLevel ¶
func WithLevel(l slog.Level) StdioOption
func WithLogger ¶
func WithLogger(logger *slog.Logger) StdioOption
func WithOut ¶
func WithOut(w io.Writer) StdioOption
type StdioOptions ¶
type StdioOptions struct {
*IOStreams
Logger *slog.Logger
Piped bool
// contains filtered or unexported fields
}
StdioOptions provides stdin-related CLI helpers, intended to be embedded in option structs.
func NewStdioOptions ¶
func NewStdioOptions() *StdioOptions
NewStdioOptions creates a new StdioOptions with default streams and logger.
func (*StdioOptions) Complete ¶
func (o *StdioOptions) Complete() error
Complete sets default values, e.g., enabling Stdin if piped input is detected.
func (*StdioOptions) Opts ¶
func (o *StdioOptions) Opts(opts ...StdioOption)
func (*StdioOptions) Validate ¶
func (o *StdioOptions) Validate() error
Validate ensures the input mode (Stdin or interactive) is used appropriately.
type TestFdReader ¶
func NewTestFdReader ¶
func (*TestFdReader) Fd ¶
func (r *TestFdReader) Fd() uintptr