Documentation
¶
Overview ¶
Package launchr provides common app functionality.
Index ¶
- Constants
- Variables
- func EnsurePath(parts ...string) error
- func EstimateTime(fn func(diff time.Duration)) func()
- func GetFsAbsPath(fs fs.FS) string
- func GetTypePkgPathName(v any) (string, string)
- func InitPluginInfo(pi *PluginInfo, p Plugin)
- func InitServiceInfo(si *ServiceInfo, s Service)
- func IsCommandErrHelp(err error) bool
- func IsSELinuxEnabled() bool
- func NewExitError(code int, msg string) error
- func RegisterPlugin(p Plugin)
- func SetLogger(l *Logger)
- type App
- type AppInternal
- type AppVersion
- type CobraPlugin
- type Command
- type CommandGroup
- type Config
- type ConfigAware
- type ExitError
- type GenerateConfig
- type GeneratePlugin
- type In
- type LogLevel
- type LogOptions
- type Logger
- type ManagedFS
- type MapItem
- type OnAppInitPlugin
- type Out
- type Plugin
- type PluginInfo
- type PluginManager
- type PluginsMap
- type Service
- type ServiceInfo
- type Slog
- type Streams
- 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 PkgPath = "github.com/launchrctl/launchr"
PkgPath is a main module path.
Variables ¶
var (
ErrNoConfigFile = errors.New("config file is not found") // ErrNoConfigFile when config file doesn't exist in FS.
)
Functions ¶
func EnsurePath ¶
EnsurePath creates all directories in the 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 GetFsAbsPath ¶
GetFsAbsPath returns absolute path for a fs.FS struct.
func GetTypePkgPathName ¶ added in v0.1.0
GetTypePkgPathName returns type package path and name for internal usage.
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 IsSELinuxEnabled ¶ added in v0.16.0
func IsSELinuxEnabled() bool
IsSELinuxEnabled checks if selinux is enabled on the system.
func NewExitError ¶ added in v0.16.4
NewExitError creates a new ExitError.
func RegisterPlugin ¶ added in v0.1.0
func RegisterPlugin(p Plugin)
RegisterPlugin add a plugin to global pull.
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.
AddService(s Service)
// GetService retrieves a service of type [v] and assigns it to [v].
// Panics if a service is not found.
GetService(v any)
// 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
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
BuiltWith string
CoreVersion string
CoreReplace string
Plugins []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 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 interface {
Service
// DirPath returns an absolute path to config directory.
DirPath() string
// Path provides an absolute path to launchr config directory.
Path(parts ...string) string
// Exists checks if key exists in config. Key level delimiter is dot.
// For example - `path.to.something`.
Exists(key string) bool
// Get returns a value by key to a parameter v. Parameter v must be a pointer to a value.
// Error may be returned on decode.
Get(key string, v any) error
}
Config is a launchr config storage interface.
func ConfigFromFS ¶ added in v0.1.0
ConfigFromFS parses launchr app config directory and its content.
type ConfigAware ¶ added in v0.1.0
type ConfigAware interface {
// SetLaunchrConfig sets a launchr config to the struct.
SetLaunchrConfig(Config)
}
ConfigAware provides an interface for structs to support launchr configuration setting.
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 supporting 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) CheckTty ¶ added in v0.16.0
CheckTty checks if we are trying to attach to a container tty from a non-tty client input stream, and if so, returns an error.
func (*In) FD ¶ added in v0.16.0
func (s *In) FD() uintptr
FD returns the file descriptor number for this stream.
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) 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.
func (*In) SetRawTerminal ¶ added in v0.16.0
SetRawTerminal sets raw mode on the input terminal.
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. )
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.
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) GetTtySize ¶ added in v0.16.0
GetTtySize returns the height and width in characters of the tty.
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.
func (*Out) SetRawTerminal ¶ added in v0.16.0
SetRawTerminal sets raw mode on the input terminal.
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 interface {
Service
All() PluginsMap
}
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 Service ¶
type Service interface {
ServiceInfo() ServiceInfo
}
Service is a common interface for a service to register.
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 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() io.Writer
}
Streams is an interface which exposes the standard input and output streams.
func NoopStreams ¶ added in v0.16.0
func NoopStreams() Streams
NoopStreams provides streams like /dev/null.
func StandardStreams ¶ added in v0.16.0
func StandardStreams() Streams
StandardStreams sets a cli in, out and err streams with the standard streams.
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 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.