Documentation
¶
Overview ¶
Package launchr provides common app functionality.
Index ¶
- Constants
- Variables
- func Cleanup() error
- func ConvertWindowsPath(windowsPath string) string
- func EnsurePath(parts ...string) error
- func EscapePathString(s string) string
- func EstimateTime(fn func(diff time.Duration)) func()
- func Executable() string
- func FsRealpath(fsys fs.FS) string
- func GetRandomString(length int) string
- func GetTypePkgPathName(v any) (string, string)
- func Getenv(key string) string
- func HandleSignals(ctx context.Context, sigc <-chan os.Signal, ...)
- func InitPluginInfo(pi *PluginInfo, p Plugin)
- func InitServiceInfo(si *ServiceInfo, s Service)
- func IsCommandErrHelp(err error) bool
- func IsHiddenPath(path string) bool
- func IsSELinuxEnabled() bool
- func IsSystemPath(root string, path string) bool
- func KnownBashPaths() []string
- func MkdirTemp(pattern string, keep bool) (string, error)
- func MustAbs(path string) string
- func MustSubFS(fsys fs.FS, path string) fs.FS
- func NewExitError(code int, msg string) error
- func NewMaskingWriter(wrappedWriter io.Writer, mask *SensitiveMask) io.WriteCloser
- func NotifySignals(sig ...os.Signal) chan os.Signal
- func RegisterCleanupFn(fn cleanupFn)
- func RegisterPlugin(p Plugin)
- func SetLogger(l *Logger)
- func StdInOutErr() (stdIn io.ReadCloser, stdOut, stdErr io.Writer)
- func StopCatchSignals(sigc chan os.Signal)
- type App
- type AppInternal
- type AppVersion
- type CmdEarlyParsed
- type CobraPlugin
- type Command
- type CommandGroup
- type Config
- type EnvVar
- type ExitError
- type GenerateConfig
- type GeneratePlugin
- type In
- func (i *In) Close() error
- func (s *In) FD() uintptr
- func (s *In) Fd() uintptr
- func (s *In) IsDiscard() bool
- func (s *In) IsTerminal() bool
- func (i *In) Read(p []byte) (int, error)
- func (i *In) Reader() io.ReadCloser
- func (s *In) RestoreTerminal()
- func (s *In) SetIsTerminal(isTerminal bool)
- func (i *In) SetRawTerminal() (err error)
- type LockedFile
- type LogLevel
- type LogOptions
- type Logger
- type ManagedFS
- type MapItem
- type MaskingWriter
- type OnAppInitPlugin
- type Out
- func (o *Out) Close() error
- func (s *Out) FD() uintptr
- func (s *Out) Fd() uintptr
- func (o *Out) GetTtySize() (uint, uint)
- func (s *Out) IsDiscard() bool
- func (s *Out) IsTerminal() bool
- func (s *Out) RestoreTerminal()
- func (s *Out) SetIsTerminal(isTerminal bool)
- func (o *Out) SetRawTerminal() (err error)
- func (o *Out) Write(p []byte) (int, error)
- func (o *Out) Writer() io.Writer
- type PersistentPreRunPlugin
- type Plugin
- type PluginInfo
- type PluginManager
- type PluginsMap
- type SensitiveMask
- func (p *SensitiveMask) AddString(s string)
- func (p *SensitiveMask) Clone() *SensitiveMask
- func (p *SensitiveMask) MaskWriter(w io.Writer) io.WriteCloser
- func (p *SensitiveMask) ReplaceAll(b []byte) (resultBytes []byte, lastBefore, lastAfter int)
- func (p *SensitiveMask) ServiceCreate(_ *ServiceManager) Service
- func (p *SensitiveMask) ServiceInfo() ServiceInfo
- func (p *SensitiveMask) String() string
- type Service
- type ServiceCreate
- type ServiceInfo
- type ServiceManager
- type SliceSeqStateful
- type Slog
- type Streams
- type StreamsModifierFn
- type Template
- type Terminal
- func (t *Terminal) Basic() TextPrinter
- func (t *Terminal) DisableOutput()
- func (t *Terminal) EnableOutput()
- func (t *Terminal) Error() TextPrinter
- func (t *Terminal) Info() TextPrinter
- func (t *Terminal) Print(a ...any)
- func (t *Terminal) Printf(format string, a ...any)
- func (t *Terminal) Printfln(format string, a ...any)
- func (t *Terminal) Println(a ...any)
- func (t *Terminal) SetOutput(w io.Writer)
- func (t *Terminal) Success() TextPrinter
- func (t *Terminal) Warning() TextPrinter
- func (t *Terminal) Write(p []byte) (int, error)
- type TextPrinter
Constants ¶
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.
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.
const PkgPath = "github.com/launchrctl/launchr"
PkgPath is a main module path.
Variables ¶
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.
var (
ErrNoConfigFile = errors.New("config file is not found") // ErrNoConfigFile when config file doesn't exist in FS.
)
Common errors.
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
ConvertWindowsPath converts Windows paths to Docker-compatible paths
func EnsurePath ¶
EnsurePath creates all directories in the path.
func EscapePathString ¶ added in v0.22.0
EscapePathString escapes characters that may be incorrectly treated as a string like backslash "\" in a Windows path.
func EstimateTime ¶ added in v0.16.0
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
FsRealpath returns absolute path for a fs.FS interface.
func GetRandomString ¶ added in v0.21.0
GetRandomString generates a random alphanumeric string of the given length.
func GetTypePkgPathName ¶ added in v0.1.0
GetTypePkgPathName returns type package path and name for internal usage.
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
IsCommandErrHelp checks if an error is a flag help err used for intercommunication.
func IsHiddenPath ¶ added in v0.17.1
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
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
MkdirTemp creates a temporary directory. It tries to create a directory in memory (tmpfs). The temp directory is removed when the app terminates.
func MustSubFS ¶ added in v0.18.0
MustSubFS returns an [FS] corresponding to the subtree rooted at fsys's dir.
func NewExitError ¶ added in v0.16.4
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
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 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
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 (*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
Command is a type alias for cobra.Command. to reduce direct dependency on cobra in packages.
type CommandGroup ¶ added in v0.16.0
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
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
EnvString returns an os string of env variable with a value val.
func (EnvVar) String ¶ added in v0.19.0
String implements fmt.Stringer interface.
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.
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) 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) 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
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
LogLevelFromString translates a log level string to
func (LogLevel) String ¶ added in v0.19.0
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 NewConsoleLogger ¶ added in v0.16.0
NewConsoleLogger creates a default console logger.
func NewJSONHandlerLogger ¶ added in v0.16.0
NewJSONHandlerLogger creates a logger with a io.Writer and JSON output.
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.
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 (*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
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
SetRawTerminal sets raw mode on the input terminal.
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
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.
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
Print implements TextPrinter interface.
func (*Terminal) Printf ¶ added in v0.16.0
Printf implements TextPrinter interface.
func (*Terminal) Printfln ¶ added in v0.16.0
Printfln implements TextPrinter interface.
func (*Terminal) Println ¶ added in v0.16.0
Println implements TextPrinter interface.
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.
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.