launchr

package
v0.22.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 1, 2025 License: Apache-2.0 Imports: 37 Imported by: 0

Documentation

Overview

Package launchr provides common app functionality.

Index

Constants

View Source
const (
	// EnvVarRootParentPID defines parent process id. May be used by forked processes.
	EnvVarRootParentPID = EnvVar("root_ppid")
	// EnvVarActionsPath defines path where to search for actions.
	EnvVarActionsPath = EnvVar("actions_path")
	// EnvVarLogLevel defines currently set log level, see --log-level or -v flag.
	EnvVarLogLevel = EnvVar("log_level")
	// EnvVarLogFormat defines currently set log format, see --log-format flag.
	EnvVarLogFormat = EnvVar("log_format")
	// EnvVarQuietMode defines if the application should output anything, see --quiet flag.
	EnvVarQuietMode = EnvVar("quiet_mode")
)

Application environment variables.

View Source
const (
	LogLevelStrDisabled string = "NONE"  // LogLevelStrDisabled does never print.
	LogLevelStrDebug    string = "DEBUG" // LogLevelStrDebug is the log level for debug.
	LogLevelStrInfo     string = "INFO"  // LogLevelStrInfo is the log level for info.
	LogLevelStrWarn     string = "WARN"  // LogLevelStrWarn is the log level for warnings.
	LogLevelStrError    string = "ERROR" // LogLevelStrError is the log level for errors.
)

LogLevel string constants.

View Source
const PkgPath = "github.com/launchrctl/launchr"

PkgPath is a main module path.

Variables

View Source
var DefaultTextPrinter = message.NewPrinter(language.English)

DefaultTextPrinter is a printer with a context of language. Currently only used in [jsonschema] package and not exported outside the repo. Looks promising in the future for translations.

View Source
var (
	ErrNoConfigFile = errors.New("config file is not found") // ErrNoConfigFile when config file doesn't exist in FS.
)

Common errors.

View Source
var IsGen = false

IsGen is an internal flag that indicates we are in Generate.

Functions

func Cleanup added in v0.18.0

func Cleanup() error

Cleanup runs registered cleanup functions. It is run on the termination of the application. Consider it as a global defer.

func ConvertWindowsPath added in v0.22.0

func ConvertWindowsPath(windowsPath string) string

ConvertWindowsPath converts Windows paths to Docker-compatible paths

func EnsurePath

func EnsurePath(parts ...string) error

EnsurePath creates all directories in the path.

func EscapePathString added in v0.22.0

func EscapePathString(s string) string

EscapePathString escapes characters that may be incorrectly treated as a string like backslash "\" in a Windows path.

func EstimateTime added in v0.16.0

func EstimateTime(fn func(diff time.Duration)) func()

EstimateTime returns a function that runs callback with the elapsed time between the call to timer and the call to the returned function. The returned function is intended to be used in a defer statement:

defer EstimateTime("sum", func (diff time.Duration) { ... })().

func Executable added in v0.22.0

func Executable() string

Executable returns the path name for the executable that started.

func FsRealpath added in v0.18.0

func FsRealpath(fsys fs.FS) string

FsRealpath returns absolute path for a fs.FS interface.

func GetRandomString added in v0.21.0

func GetRandomString(length int) string

GetRandomString generates a random alphanumeric string of the given length.

func GetTypePkgPathName added in v0.1.0

func GetTypePkgPathName(v any) (string, string)

GetTypePkgPathName returns type package path and name for internal usage.

func Getenv added in v0.22.0

func Getenv(key string) string

Getenv is an environment variable expand callback.

func HandleSignals added in v0.19.0

func HandleSignals(ctx context.Context, sigc <-chan os.Signal, killFn func(s os.Signal, sig string) error)

HandleSignals forwards signals to the handler.

func InitPluginInfo added in v0.1.0

func InitPluginInfo(pi *PluginInfo, p Plugin)

InitPluginInfo sets private fields for internal usage only.

func InitServiceInfo added in v0.1.0

func InitServiceInfo(si *ServiceInfo, s Service)

InitServiceInfo sets private fields for internal usage only.

func IsCommandErrHelp added in v0.16.0

func IsCommandErrHelp(err error) bool

IsCommandErrHelp checks if an error is a flag help err used for intercommunication.

func IsHiddenPath added in v0.17.1

func IsHiddenPath(path string) bool

IsHiddenPath checks if a path is hidden path.

func IsSELinuxEnabled added in v0.16.0

func IsSELinuxEnabled() bool

IsSELinuxEnabled checks if selinux is enabled on the system.

func IsSystemPath added in v0.17.1

func IsSystemPath(root string, path string) bool

IsSystemPath checks if a path is a system path.

func KnownBashPaths added in v0.22.0

func KnownBashPaths() []string

KnownBashPaths returns paths where bash can be found. Used when PATH is not available.

func MkdirTemp added in v0.18.0

func MkdirTemp(pattern string, keep bool) (string, error)

MkdirTemp creates a temporary directory. It tries to create a directory in memory (tmpfs). The temp directory is removed when the app terminates.

func MustAbs added in v0.17.1

func MustAbs(path string) string

MustAbs returns absolute filepath and panics on error.

func MustSubFS added in v0.18.0

func MustSubFS(fsys fs.FS, path string) fs.FS

MustSubFS returns an [FS] corresponding to the subtree rooted at fsys's dir.

func NewExitError added in v0.16.4

func NewExitError(code int, msg string) error

NewExitError creates a new ExitError.

func NewMaskingWriter added in v0.19.0

func NewMaskingWriter(wrappedWriter io.Writer, mask *SensitiveMask) io.WriteCloser

NewMaskingWriter initializes a new MaskingWriter.

func NotifySignals added in v0.19.0

func NotifySignals(sig ...os.Signal) chan os.Signal

NotifySignals starts watching interrupt signals.

func RegisterCleanupFn added in v0.18.0

func RegisterCleanupFn(fn cleanupFn)

RegisterCleanupFn saves a function to be executed on Cleanup.

func RegisterPlugin added in v0.1.0

func RegisterPlugin(p Plugin)

RegisterPlugin add a plugin to global pull.

func SetLogger added in v0.16.0

func SetLogger(l *Logger)

SetLogger sets the default logger.

func StdInOutErr added in v0.19.0

func StdInOutErr() (stdIn io.ReadCloser, stdOut, stdErr io.Writer)

StdInOutErr returns the standard streams (stdin, stdout, stderr).

On Windows, it attempts to turn on VT handling on all std handles if supported, or falls back to terminal emulation. On Unix, this returns the standard os.Stdin, os.Stdout and os.Stderr.

func StopCatchSignals added in v0.19.0

func StopCatchSignals(sigc chan os.Signal)

StopCatchSignals stops catching the signals and closes the specified channel.

Types

type App added in v0.1.0

type App interface {
	// Name returns app name.
	Name() string
	// GetWD provides app's working dir.
	GetWD() string
	// Streams returns application cli.
	Streams() Streams
	// SetStreams sets application streams.
	SetStreams(s Streams)
	// AddService registers a service in the app.
	// Panics if a service is not unique.
	// Deprecated: use app.Services().Add(s)
	AddService(s Service)
	// GetService retrieves a service of type [v] and assigns it to [v].
	// Panics if a service is not found.
	// Deprecated: use app.Services().Get(&v)
	GetService(v any)
	// Services returns a service manager.
	Services() *ServiceManager
	// SensitiveWriter wraps given writer with a sensitive mask.
	// Deprecated: use app.Services().Get()
	SensitiveWriter(w io.Writer) io.Writer
	// SensitiveMask returns current sensitive mask to add values to mask.
	// Deprecated: use app.Services().Get()
	SensitiveMask() *SensitiveMask

	// RegisterFS registers a File System in launchr.
	// It may be a FS for action discovery, see [action.DiscoveryFS].
	RegisterFS(fs ManagedFS)
	// GetRegisteredFS returns an array of registered File Systems.
	GetRegisteredFS() []ManagedFS
}

App stores global application state.

type AppInternal added in v0.16.0

type AppInternal interface {
	App
	RootCmd() *Command
	CmdEarlyParsed() CmdEarlyParsed
}

AppInternal is an extension to access cobra related functionality of the app. It is intended for internal use only to prevent coupling on volatile functionality.

type AppVersion added in v0.1.0

type AppVersion struct {
	Name        string
	Version     string
	OS          string
	Arch        string
	Debug       bool
	BuiltWith   string
	CoreVersion string
	CoreReplace string
	Plugins     []string
	PluginsRepl []string
}

AppVersion stores application version.

func NewVersion added in v0.1.0

func NewVersion(name, ver, bwith string, plugins PluginsMap) *AppVersion

NewVersion creates version info with used plugins info.

func Version added in v0.1.0

func Version() *AppVersion

Version provides app version info.

func (*AppVersion) Full added in v0.1.0

func (v *AppVersion) Full() string

Full outputs version string in a full format.

func (*AppVersion) Short added in v0.1.0

func (v *AppVersion) Short() string

Short outputs a short version string.

func (*AppVersion) String added in v0.2.1

func (v *AppVersion) String() string

String implements Stringer interface.

type CmdEarlyParsed added in v0.17.1

type CmdEarlyParsed struct {
	Command   string   // Command is the requested command.
	Args      []string // Args are all arguments provided in the command line.
	IsVersion bool     // IsVersion when version was requested.
	IsGen     bool     // IsGen when in generate mod.
}

CmdEarlyParsed is all parsed command information on early stage.

func EarlyPeekCommand added in v0.17.1

func EarlyPeekCommand() CmdEarlyParsed

EarlyPeekCommand parses all available information during init stage.

type CobraPlugin added in v0.1.0

type CobraPlugin interface {
	Plugin
	// CobraAddCommands is a hook called when cobra root command is available.
	// Plugins may register its command line commands here.
	CobraAddCommands(root *Command) error
}

CobraPlugin is an interface to implement a plugin for cobra.

type Command added in v0.16.0

type Command = cobra.Command

Command is a type alias for cobra.Command. to reduce direct dependency on cobra in packages.

type CommandGroup added in v0.16.0

type CommandGroup = cobra.Group

CommandGroup is a type alias for cobra.Group.

type Config added in v0.1.0

type Config = *config

Config is a launchr global config service.

func ConfigFromFS added in v0.1.0

func ConfigFromFS(root fs.FS) Config

ConfigFromFS parses launchr app config directory and its content.

type EnvVar added in v0.19.0

type EnvVar string

EnvVar defines an environment variable and provides an interface to interact with it by prefixing the current app name. For example, if "my_var" is given as the variable name and the app name is "launchr", the accessed environment variable will be "LAUNCHR_MY_VAR".

func (EnvVar) EnvString added in v0.19.0

func (key EnvVar) EnvString(val string) string

EnvString returns an os string of env variable with a value val.

func (EnvVar) Get added in v0.19.0

func (key EnvVar) Get() string

Get returns env variable value.

func (EnvVar) Set added in v0.19.0

func (key EnvVar) Set(val string) error

Set sets env variable.

func (EnvVar) String added in v0.19.0

func (key EnvVar) String() string

String implements fmt.Stringer interface.

func (EnvVar) Unset added in v0.19.0

func (key EnvVar) Unset() error

Unset unsets env variable.

type ExitError added in v0.16.4

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

ExitError is an error holding an error code of executed command.

func (ExitError) Error added in v0.16.4

func (e ExitError) Error() string

Error implements error interface.

func (ExitError) ExitCode added in v0.16.4

func (e ExitError) ExitCode() int

ExitCode returns the exit code.

type GenerateConfig added in v0.16.3

type GenerateConfig struct {
	WorkDir  string // WorkDir is where the script must consider current working directory.
	BuildDir string // BuildDir is where the script will output the result.
}

GenerateConfig defines generation config.

type GeneratePlugin added in v0.1.0

type GeneratePlugin interface {
	Plugin
	// Generate is a function called when application is generating code and assets for the build.
	Generate(config GenerateConfig) error
}

GeneratePlugin is an interface to generate arbitrarily required files before build.

type In added in v0.16.0

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

In is an input stream used by the app to read user input.

func NewIn added in v0.16.0

func NewIn(in io.ReadCloser) *In

NewIn returns a new In object from a io.ReadCloser

func (*In) Close added in v0.16.0

func (i *In) Close() error

Close implements the io.Closer interface.

func (*In) FD added in v0.16.0

func (s *In) FD() uintptr

FD returns the file descriptor number for this stream.

func (*In) Fd added in v0.21.0

func (s *In) Fd() uintptr

Fd returns the file descriptor number for this stream.

func (*In) IsDiscard added in v0.21.0

func (s *In) IsDiscard() bool

IsDiscard returns if read/write is discarded.

func (*In) IsTerminal added in v0.16.0

func (s *In) IsTerminal() bool

IsTerminal returns true if this stream is connected to a terminal.

func (*In) Read added in v0.16.0

func (i *In) Read(p []byte) (int, error)

func (*In) Reader added in v0.19.0

func (i *In) Reader() io.ReadCloser

Reader returns the wrapped reader.

func (*In) RestoreTerminal added in v0.16.0

func (s *In) RestoreTerminal()

RestoreTerminal restores normal mode to the terminal.

func (*In) SetIsTerminal added in v0.16.0

func (s *In) SetIsTerminal(isTerminal bool)

SetIsTerminal sets the boolean used for isTerminal. Used for tests only.

func (*In) SetRawTerminal added in v0.16.0

func (i *In) SetRawTerminal() (err error)

SetRawTerminal sets raw mode on the input terminal.

type LockedFile added in v0.17.1

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

LockedFile is file with a lock for other processes.

func NewLockedFile added in v0.17.1

func NewLockedFile(fname string) *LockedFile

NewLockedFile creates a new LockedFile.

func (*LockedFile) Close added in v0.17.1

func (f *LockedFile) Close() error

Close implements io.ReadWriteCloser interface.

func (*LockedFile) Filename added in v0.17.1

func (f *LockedFile) Filename() string

Filename returns file's name.

func (*LockedFile) Open added in v0.17.1

func (f *LockedFile) Open(flag int, perm os.FileMode) (err error)

Open opens a file and locks it for other..

func (*LockedFile) Read added in v0.17.1

func (f *LockedFile) Read(p []byte) (n int, err error)

Read implements io.ReadWriteCloser interface.

func (*LockedFile) Remove added in v0.17.1

func (f *LockedFile) Remove() (err error)

Remove deletes the file.

func (*LockedFile) Write added in v0.17.1

func (f *LockedFile) Write(p []byte) (n int, err error)

Write implements io.ReadWriteCloser interface.

type LogLevel added in v0.16.0

type LogLevel int

A LogLevel is the importance or severity of a log event.

const (
	LogLevelDisabled LogLevel = iota // LogLevelDisabled does never print.
	LogLevelDebug                    // LogLevelDebug is the log level for debug.
	LogLevelInfo                     // LogLevelInfo is the log level for info.
	LogLevelWarn                     // LogLevelWarn is the log level for warnings.
	LogLevelError                    // LogLevelError is the log level for errors.
)

Log levels.

func LogLevelFromString added in v0.19.0

func LogLevelFromString(s string) LogLevel

LogLevelFromString translates a log level string to

func (LogLevel) String added in v0.19.0

func (l LogLevel) String() string

String implements fmt.Stringer interface.

type LogOptions added in v0.16.0

type LogOptions interface {
	// Level returns the currently set log level.
	Level() LogLevel
	// SetLevel sets log level.
	SetLevel(l LogLevel)
	// SetOutput sets logger output.
	SetOutput(w io.Writer)
}

LogOptions is a common interface to allow adjusting the logger.

type Logger added in v0.16.0

type Logger struct {
	*Slog
	LogOptions
}

Logger is a logger and its config holder struct.

func Log added in v0.16.0

func Log() *Logger

Log returns the default logger.

func NewConsoleLogger added in v0.16.0

func NewConsoleLogger(w io.Writer) *Logger

NewConsoleLogger creates a default console logger.

func NewJSONHandlerLogger added in v0.16.0

func NewJSONHandlerLogger(w io.Writer) *Logger

NewJSONHandlerLogger creates a logger with a io.Writer and JSON output.

func NewTextHandlerLogger added in v0.16.0

func NewTextHandlerLogger(w io.Writer) *Logger

NewTextHandlerLogger creates a logger with a io.Writer and plain slog output.

type ManagedFS added in v0.5.5

type ManagedFS interface {
	fs.FS
	FS() fs.FS
}

ManagedFS is a common interface for FS registered in launchr.

type MapItem added in v0.16.3

type MapItem[K, V any] struct {
	K K // K is a key of the map item.
	V V // V is a value of the map item.
}

MapItem is a helper struct used to return an ordered map as a slice.

func GetPluginByType added in v0.17.1

func GetPluginByType[T Plugin](mngr PluginManager) []MapItem[PluginInfo, T]

GetPluginByType returns specific plugins from the app.

type MaskingWriter added in v0.19.0

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

MaskingWriter is a writer that masks sensitive data in the input stream. It buffers data to handle cases where sensitive data spans across writes.

func (*MaskingWriter) Close added in v0.19.0

func (m *MaskingWriter) Close() error

Close flushes any remaining data in the buf.

func (*MaskingWriter) Write added in v0.19.0

func (m *MaskingWriter) Write(p []byte) (n int, err error)

Write applies masking to the input and writes to the wrapped writer.

type OnAppInitPlugin added in v0.1.0

type OnAppInitPlugin interface {
	Plugin
	// OnAppInit is hook function called on application initialisation.
	// Plugins may save app global object, retrieve or provide services here.
	OnAppInit(app App) error
}

OnAppInitPlugin is an interface to implement a plugin for app initialisation.

type Out added in v0.16.0

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

Out is an output stream used by the app to write normal program output.

func NewOut added in v0.16.0

func NewOut(out io.Writer) *Out

NewOut returns a new Out object from an io.Writer.

func (*Out) Close added in v0.21.0

func (o *Out) Close() error

Close implement io.Closer

func (*Out) FD added in v0.16.0

func (s *Out) FD() uintptr

FD returns the file descriptor number for this stream.

func (*Out) Fd added in v0.21.0

func (s *Out) Fd() uintptr

Fd returns the file descriptor number for this stream.

func (*Out) GetTtySize added in v0.16.0

func (o *Out) GetTtySize() (uint, uint)

GetTtySize returns the height and width in characters of the tty.

func (*Out) IsDiscard added in v0.21.0

func (s *Out) IsDiscard() bool

IsDiscard returns if read/write is discarded.

func (*Out) IsTerminal added in v0.16.0

func (s *Out) IsTerminal() bool

IsTerminal returns true if this stream is connected to a terminal.

func (*Out) RestoreTerminal added in v0.16.0

func (s *Out) RestoreTerminal()

RestoreTerminal restores normal mode to the terminal.

func (*Out) SetIsTerminal added in v0.16.0

func (s *Out) SetIsTerminal(isTerminal bool)

SetIsTerminal sets the boolean used for isTerminal. Used for tests only.

func (*Out) SetRawTerminal added in v0.16.0

func (o *Out) SetRawTerminal() (err error)

SetRawTerminal sets raw mode on the input terminal.

func (*Out) Write added in v0.16.0

func (o *Out) Write(p []byte) (int, error)

func (*Out) Writer added in v0.19.0

func (o *Out) Writer() io.Writer

Writer returns the wrapped writer.

type PersistentPreRunPlugin added in v0.19.0

type PersistentPreRunPlugin interface {
	Plugin
	PersistentPreRun(cmd *Command, args []string) error
}

PersistentPreRunPlugin is an interface to implement a plugin to run before any command is run and all arguments are parsed.

type Plugin added in v0.1.0

type Plugin interface {
	// PluginInfo requests a type to provide information about the plugin.
	PluginInfo() PluginInfo
}

Plugin is a common interface for launchr plugins.

type PluginInfo added in v0.1.0

type PluginInfo struct {
	// Weight defines the order of plugins calling. @todo rework to a real dependency resolving.
	Weight int
	// contains filtered or unexported fields
}

PluginInfo provides information about the plugin and is used as a unique data to identify a plugin.

func (PluginInfo) GetPackagePath added in v0.9.0

func (p PluginInfo) GetPackagePath() string

GetPackagePath returns the package path of the PluginInfo.

func (PluginInfo) String added in v0.1.0

func (p PluginInfo) String() string

type PluginManager added in v0.1.0

type PluginManager = pluginManagerMap

PluginManager handles plugins.

func NewPluginManagerWithRegistered added in v0.1.0

func NewPluginManagerWithRegistered() PluginManager

NewPluginManagerWithRegistered creates PluginManager with registered plugins.

type PluginsMap added in v0.1.0

type PluginsMap = map[PluginInfo]Plugin

PluginsMap is a type alias for plugins map.

type SensitiveMask added in v0.19.0

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

SensitiveMask replaces sensitive strings with a mask.

func NewSensitiveMask added in v0.19.0

func NewSensitiveMask(mask string) *SensitiveMask

NewSensitiveMask creates a sensitive mask replacing strings with mask value.

func (*SensitiveMask) AddString added in v0.19.0

func (p *SensitiveMask) AddString(s string)

AddString adds a string to mask.

func (*SensitiveMask) Clone added in v0.22.0

func (p *SensitiveMask) Clone() *SensitiveMask

Clone creates a copy of a sensitive mask.

func (*SensitiveMask) MaskWriter added in v0.22.0

func (p *SensitiveMask) MaskWriter(w io.Writer) io.WriteCloser

MaskWriter returns a wrapped writer with masked output.

func (*SensitiveMask) ReplaceAll added in v0.19.0

func (p *SensitiveMask) ReplaceAll(b []byte) (resultBytes []byte, lastBefore, lastAfter int)

ReplaceAll replaces sensitive strings in the given bytes b. It returns the modified string and last index of replaced parts to track where the last change was made for before change and after change bytes.

func (*SensitiveMask) ServiceCreate added in v0.22.0

func (p *SensitiveMask) ServiceCreate(_ *ServiceManager) Service

ServiceCreate implements ServiceCreate interface.

func (*SensitiveMask) ServiceInfo added in v0.22.0

func (p *SensitiveMask) ServiceInfo() ServiceInfo

ServiceInfo implements Service interface.

func (*SensitiveMask) String added in v0.19.0

func (p *SensitiveMask) String() string

String implements fmt.Stringer to occasionally not render sensitive data.

type Service

type Service interface {
	ServiceInfo() ServiceInfo
}

Service is a common interface for a service to register.

type ServiceCreate added in v0.22.0

type ServiceCreate interface {
	Service
	ServiceCreate(svc *ServiceManager) Service
}

ServiceCreate allows creating a service using a ServiceManager. TODO: Merge with Service when refactored.

type ServiceInfo

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

ServiceInfo provides service info for its initialization.

func (ServiceInfo) String added in v0.1.0

func (s ServiceInfo) String() string

type ServiceManager added in v0.22.0

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

ServiceManager is a basic Dependency Injection container storing registered Service.

func NewServiceManager added in v0.22.0

func NewServiceManager() *ServiceManager

NewServiceManager initializes ServiceManager.

func (*ServiceManager) Add added in v0.22.0

func (sm *ServiceManager) Add(s Service)

Add registers a service. Panics if a service is not unique.

func (*ServiceManager) Get added in v0.22.0

func (sm *ServiceManager) Get(v any)

Get retrieves a service of type [v] and assigns it to [v]. Panics if a service is not found.

type SliceSeqStateful added in v0.19.0

type SliceSeqStateful[V any] struct {
	// contains filtered or unexported fields
}

SliceSeqStateful allows for resuming iteration after slice grows.

func NewSliceSeqStateful added in v0.19.0

func NewSliceSeqStateful[V any](slice *[]V) *SliceSeqStateful[V]

NewSliceSeqStateful creates a new SliceSeqStateful.

func (*SliceSeqStateful[V]) Reset added in v0.19.0

func (seq *SliceSeqStateful[V]) Reset()

Reset resets current index to start.

func (*SliceSeqStateful[V]) Seq added in v0.19.0

func (seq *SliceSeqStateful[V]) Seq() iter.Seq[V]

Seq returns a slice iterator.

type Slog added in v0.16.0

type Slog = slog.Logger

Slog is an alias for a go structured logger slog.Logger to reduce visible dependencies.

type Streams added in v0.16.0

type Streams interface {
	// In returns the reader used for stdin.
	In() *In
	// Out returns the writer used for stdout.
	Out() *Out
	// Err returns the writer used for stderr.
	Err() *Out
	io.Closer
}

Streams is an interface which exposes the standard input and output streams.

func MaskedStdStreams added in v0.19.0

func MaskedStdStreams(mask *SensitiveMask) Streams

MaskedStdStreams sets a cli in, out and err streams with the standard streams and with masking of sensitive data.

func NewBasicStreams added in v0.19.0

func NewBasicStreams(in io.ReadCloser, out io.Writer, err io.Writer, fns ...StreamsModifierFn) Streams

NewBasicStreams creates streams with given in, out and err streams. Give decorate functions to extend functionality.

func NoopStreams added in v0.16.0

func NoopStreams() Streams

NoopStreams provides streams like /dev/null.

type StreamsModifierFn added in v0.19.0

type StreamsModifierFn func(streams *appCli)

StreamsModifierFn is a decorator function for a stream.

func WithSensitiveMask added in v0.19.0

func WithSensitiveMask(m *SensitiveMask) StreamsModifierFn

WithSensitiveMask decorates streams with a given mask.

type Template added in v0.16.0

type Template struct {
	Tmpl string // Tmpl is a template string.
	Data any    // Data is a template data.
}

Template provides templating functionality to generate files.

func (Template) Generate added in v0.16.0

func (t Template) Generate(w io.Writer) error

Generate executes a template and writes it.

func (Template) WriteFile added in v0.16.0

func (t Template) WriteFile(name string) error

WriteFile creates/overwrites a file and executes the template with it.

type Terminal added in v0.16.0

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

Terminal prints formatted text to the console.

func NewTerminal added in v0.21.0

func NewTerminal() *Terminal

NewTerminal creates a new instance of Terminal

func Term added in v0.16.0

func Term() *Terminal

Term returns default Terminal to print application messages to the console.

func (*Terminal) Basic added in v0.16.0

func (t *Terminal) Basic() TextPrinter

Basic returns a default basic printer.

func (*Terminal) DisableOutput added in v0.16.0

func (t *Terminal) DisableOutput()

DisableOutput disables the output.

func (*Terminal) EnableOutput added in v0.16.0

func (t *Terminal) EnableOutput()

EnableOutput enables the output.

func (*Terminal) Error added in v0.16.0

func (t *Terminal) Error() TextPrinter

Error returns a prefixed printer, which can be used to print text with an "error" prefix.

func (*Terminal) Info added in v0.16.0

func (t *Terminal) Info() TextPrinter

Info returns a prefixed printer, which can be used to print text with an "info" prefix.

func (*Terminal) Print added in v0.16.0

func (t *Terminal) Print(a ...any)

Print implements TextPrinter interface.

func (*Terminal) Printf added in v0.16.0

func (t *Terminal) Printf(format string, a ...any)

Printf implements TextPrinter interface.

func (*Terminal) Printfln added in v0.16.0

func (t *Terminal) Printfln(format string, a ...any)

Printfln implements TextPrinter interface.

func (*Terminal) Println added in v0.16.0

func (t *Terminal) Println(a ...any)

Println implements TextPrinter interface.

func (*Terminal) SetOutput added in v0.16.0

func (t *Terminal) SetOutput(w io.Writer)

SetOutput sets an output to target writer.

func (*Terminal) Success added in v0.16.0

func (t *Terminal) Success() TextPrinter

Success returns a prefixed printer, which can be used to print text with a "success" Prefix.

func (*Terminal) Warning added in v0.16.0

func (t *Terminal) Warning() TextPrinter

Warning returns a prefixed printer, which can be used to print text with a "warning" prefix.

func (*Terminal) Write added in v0.16.0

func (t *Terminal) Write(p []byte) (int, error)

Write implements io.Writer interface.

type TextPrinter added in v0.16.0

type TextPrinter interface {
	// SetOutput sets where the output will be printed.
	SetOutput(w io.Writer)

	// Print formats using the default formats for its operands and writes to standard output.
	// Spaces are added between operands when neither is a string.
	Print(a ...any)

	// Println formats using the default formats for its operands and writes to standard output.
	// Spaces are always added between operands and a newline is appended.
	Println(a ...any)

	// Printf formats according to a format specifier and writes to standard output.
	Printf(format string, a ...any)

	// Printfln formats according to a format specifier and writes to standard output.
	// Spaces are always added between operands and a newline is appended.
	Printfln(format string, a ...any)
}

TextPrinter contains methods to print formatted text to the console or return it as a string.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL