Documentation
¶
Overview ¶
Package command implements both rules and profiles, providing a single API for command execution, file watching, and event handling.
Index ¶
- Variables
- type Commander
- type Config
- type Event
- type EventCancel
- type EventConfigure
- type EventEnd
- type EventListResources
- type EventOpenResource
- type EventStart
- type FilteredFS
- func (f *FilteredFS) Close() error
- func (f *FilteredFS) Name() string
- func (f *FilteredFS) Open(name string) (*os.File, error)
- func (f *FilteredFS) OpenFile(name string, flag int, perm fs.FileMode) (*os.File, error)
- func (f *FilteredFS) ReadDir(name string) ([]os.DirEntry, error)
- func (f *FilteredFS) Stat(name string) (fs.FileInfo, error)
- type Output
- type OutputOpt
- type ProfileMatch
- type RootFS
- type Runner
- func (cr *Runner) Close()
- func (cr *Runner) Configure(opts ...RunnerOpt) error
- func (cr *Runner) ConfigureContext(ctx context.Context, opts ...RunnerOpt) error
- func (cr *Runner) FS() (*FilteredFS, error)
- func (cr *Runner) FindProfile(path string) (string, *profile.Profile, error)
- func (cr *Runner) FindProfiles(path string) ([]ProfileMatch, error)
- func (cr *Runner) GetCurrentProfile() (string, *profile.Profile)
- func (cr *Runner) GetPath() string
- func (cr *Runner) GetProfiles() map[string]*profile.Profile
- func (cr *Runner) Run() Output
- func (cr *Runner) RunContext(ctx context.Context) Output
- func (cr *Runner) RunOnEvent()
- func (cr *Runner) RunPlugin(name string) Output
- func (cr *Runner) RunPluginContext(ctx context.Context, name string) Output
- func (cr *Runner) SendEvent(evt Event)
- func (cr *Runner) SetProfile(name string) error
- func (cr *Runner) String() string
- func (cr *Runner) Subscribe(ch chan<- Event)
- type RunnerOpt
- func WithAutoProfile() RunnerOpt
- func WithCustomProfile(name string, p *profile.Profile) RunnerOpt
- func WithExtraArgs(args ...string) RunnerOpt
- func WithPath(path string) RunnerOpt
- func WithProfile(name string) RunnerOpt
- func WithProfiles(profiles map[string]*profile.Profile) RunnerOpt
- func WithRules(rs []*rule.Rule) RunnerOpt
- func WithWatch(watch bool) RunnerOpt
- func WithWatcherBatchDuration(dur time.Duration) RunnerOpt
- type Static
- func (rg *Static) Close()
- func (rg *Static) Configure(_ ...RunnerOpt) error
- func (rg *Static) ConfigureContext(_ context.Context, _ ...RunnerOpt) error
- func (rg *Static) FS() (*FilteredFS, error)
- func (rg *Static) FindProfile(_ string) (string, *profile.Profile, error)
- func (rg *Static) FindProfiles(_ string) ([]ProfileMatch, error)
- func (rg *Static) GetCurrentProfile() (string, *profile.Profile)
- func (rg *Static) GetPath() string
- func (rg *Static) GetProfiles() map[string]*profile.Profile
- func (rg *Static) GetRules() []*rule.Rule
- func (rg *Static) Run() Output
- func (rg *Static) RunContext(ctx context.Context) Output
- func (rg *Static) RunOnEvent()
- func (rg *Static) RunPlugin(_ string) Output
- func (rg *Static) RunPluginContext(ctx context.Context, _ string) Output
- func (rg *Static) SendEvent(evt Event)
- func (rg *Static) String() string
- func (rg *Static) Subscribe(ch chan<- Event)
- type Type
Constants ¶
This section is empty.
Variables ¶
var ErrNoCommandForPath = errors.New("no command for path")
ErrNoCommandForPath is returned when no command is found for a path.
Functions ¶
This section is empty.
Types ¶
type Commander ¶ added in v0.25.0
type Commander interface {
Run() Output
RunContext(ctx context.Context) Output
RunOnEvent()
String() string
Subscribe(ch chan<- Event)
GetProfiles() map[string]*profile.Profile
GetCurrentProfile() (string, *profile.Profile)
GetPath() string
FindProfiles(path string) ([]ProfileMatch, error)
Configure(opts ...RunnerOpt) error
ConfigureContext(ctx context.Context, opts ...RunnerOpt) error
RunPlugin(name string) Output
RunPluginContext(ctx context.Context, name string) Output
FS() (*FilteredFS, error)
SendEvent(evt Event)
}
type Config ¶
type Config struct {
// Profiles contains a map of profile names to profile configurations.
Profiles map[string]*profile.Profile `json:"profiles,omitempty" jsonschema:"title=Profiles"`
// Rules defines the rules for matching files to profiles.
Rules []*rule.Rule `json:"rules,omitempty" jsonschema:"title=Rules"`
}
Config defines the core (non-UI) kat configuration.
func NewConfig ¶
func NewConfig() *Config
NewConfig creates a new Config with default profiles and rules.
func (*Config) EnsureDefaults ¶
func (c *Config) EnsureDefaults()
type EventCancel ¶
type EventCancel struct {
// contains filtered or unexported fields
}
EventCancel indicates that a command execution has been canceled.
func NewEventCancel ¶ added in v0.25.0
func NewEventCancel(ctx context.Context) EventCancel
NewEventCancel creates a new EventCancel with the given context.
func (EventCancel) GetContext ¶ added in v0.25.0
func (e EventCancel) GetContext() context.Context
GetContext returns the context associated with the EventCancel.
type EventConfigure ¶ added in v0.25.0
type EventConfigure struct {
// contains filtered or unexported fields
}
EventConfigure indicates that a command has been configured (or re-configured).
func NewEventConfigure ¶ added in v0.25.0
func NewEventConfigure(ctx context.Context) EventConfigure
NewEventConfigure creates a new EventConfigure with the given context.
func (EventConfigure) GetContext ¶ added in v0.25.0
func (e EventConfigure) GetContext() context.Context
GetContext returns the context associated with the EventConfigure.
type EventEnd ¶
type EventEnd struct {
Output Output
// contains filtered or unexported fields
}
EventEnd indicates that a command execution has ended. This event carries the output of the command execution, which could be an error if the command failed.
func NewEventEnd ¶ added in v0.25.0
NewEventEnd creates a new EventEnd with the given context and output.
func (EventEnd) GetContext ¶ added in v0.25.0
GetContext returns the context associated with the EventEnd.
type EventListResources ¶ added in v0.25.0
type EventListResources struct {
// contains filtered or unexported fields
}
EventListResources indicates that a list of resources was requested.
func NewEventListResources ¶ added in v0.25.0
func NewEventListResources(ctx context.Context) EventListResources
NewEventListResources creates a new EventListResources with the given context.
func (EventListResources) GetContext ¶ added in v0.25.0
func (e EventListResources) GetContext() context.Context
GetContext returns the context associated with the EventListResources.
type EventOpenResource ¶ added in v0.25.0
EventOpenResource indicates that a specific resource was opened.
func NewEventOpenResource ¶ added in v0.25.0
func NewEventOpenResource(ctx context.Context, resource kube.Resource) EventOpenResource
NewEventOpenResource creates a new EventOpenResource with the given context and resource.
func (EventOpenResource) GetContext ¶ added in v0.25.0
func (e EventOpenResource) GetContext() context.Context
GetContext returns the context associated with the EventOpenResource.
type EventStart ¶
type EventStart struct {
Type Type
// contains filtered or unexported fields
}
EventStart indicates that a command execution has started.
func NewEventStart ¶ added in v0.25.0
func NewEventStart(ctx context.Context, t Type) EventStart
NewEventStart creates a new EventStart with the given context and type.
func (EventStart) GetContext ¶ added in v0.25.0
func (e EventStart) GetContext() context.Context
GetContext returns the context associated with the EventStart.
type FilteredFS ¶ added in v0.25.0
type FilteredFS struct {
// contains filtered or unexported fields
}
FilteredFS wraps a RootFS and filters the tree based on rule matches. It hides files and directories that do not match any rules. Note that it does not directly prevent access to any files in the tree. (However, os.Root will prevent leaving the initially provided directory tree.)
func NewFilteredFS ¶ added in v0.25.0
func NewFilteredFS(root RootFS, rules ...*rule.Rule) (*FilteredFS, error)
NewFilteredFS creates a new FilteredFS with the given directory path and rules.
func NewFilteredFSFromPath ¶ added in v0.25.0
func NewFilteredFSFromPath(dirPath string, rules ...*rule.Rule) (*FilteredFS, error)
func (*FilteredFS) Close ¶ added in v0.25.0
func (f *FilteredFS) Close() error
Close closes the FilteredFS. After Close is called, methods on FilteredFS return errors.
func (*FilteredFS) Name ¶ added in v0.25.0
func (f *FilteredFS) Name() string
Name returns the name of the directory presented to OpenRoot. It is safe to call Name after FilteredFS.Close.
func (*FilteredFS) Open ¶ added in v0.25.0
func (f *FilteredFS) Open(name string) (*os.File, error)
Open opens the named file in the root for reading. See os.Open for more details.
func (*FilteredFS) OpenFile ¶ added in v0.25.0
OpenFile opens the named file in the root. See os.OpenFile for more details. If perm contains bits other than the nine least-significant bits (0o777), OpenFile returns an error.
func (*FilteredFS) ReadDir ¶ added in v0.25.0
func (f *FilteredFS) ReadDir(name string) ([]os.DirEntry, error)
ReadDir reads the named directory, returning any entries that match at least one rule.Rule (recursively), sorted by filename.
func (*FilteredFS) Stat ¶ added in v0.25.0
func (f *FilteredFS) Stat(name string) (fs.FileInfo, error)
Stat returns a fs.FileInfo describing the named file in the root. See os.Stat for more details.
type Output ¶
type ProfileMatch ¶ added in v0.25.0
type RootFS ¶ added in v0.25.0
type RootFS interface {
Close() error
FS() fs.FS
Name() string
Open(name string) (*os.File, error)
OpenFile(name string, flag int, perm os.FileMode) (*os.File, error)
Remove(name string) error
Stat(name string) (os.FileInfo, error)
}
RootFS is an interface for a filesystem that quacks like os.Root.
type Runner ¶
type Runner struct {
// contains filtered or unexported fields
}
Runner wraps one or more Rule objects. It manages:
- File-to-command mappings.
- Filesystem notifications / watching.
- Concurrent command execution.
func NewRunner ¶
NewRunner creates a new Runner. It uses the current working directory as the filesystem root.
func NewRunnerWithRoot ¶ added in v0.25.0
NewRunner creates a new Runner using the provided RootFS. This is not a normal opt since it cannot be re-configured after the runner has been created.
func (*Runner) ConfigureContext ¶ added in v0.25.0
Configure applies options to an existing runner. This allows reconfiguration after creation.
func (*Runner) FS ¶ added in v0.25.0
func (cr *Runner) FS() (*FilteredFS, error)
FS creates a FilteredFS for the runner that hides directories and files unless they match at least one of the configured rules.
func (*Runner) FindProfile ¶ added in v0.25.0
func (*Runner) FindProfiles ¶ added in v0.25.0
func (cr *Runner) FindProfiles(path string) ([]ProfileMatch, error)
FindProfiles finds matching profiles for the given path using the configured rules. The results are returned in order of priority.
func (*Runner) GetProfiles ¶ added in v0.25.0
func (*Runner) Run ¶
RunFirstMatch executes the first matching command for the given path. If path is a file, it checks for direct matches. If path is a directory, it checks all files in the directory for matches.
func (*Runner) RunContext ¶
RunContext executes the first matching command for the given path with the provided context. If path is a file, it checks for direct matches. If path is a directory, it checks all files in the directory for matches. The context can be used for cancellation, timeouts, and tracing.
func (*Runner) RunOnEvent ¶
func (cr *Runner) RunOnEvent()
RunOnEvent listens for file system events and runs the command in response. The output should be collected via Runner.Subscribe.
func (*Runner) RunPluginContext ¶
RunPluginContext executes a plugin by name with the provided context.
func (*Runner) SendEvent ¶ added in v0.25.0
SendEvent allows external components to send events to all listeners.
func (*Runner) SetProfile ¶ added in v0.25.0
type RunnerOpt ¶
func WithAutoProfile ¶ added in v0.25.0
func WithAutoProfile() RunnerOpt
WithAutoProfile configures the runner to determine the profile via rules.
func WithCustomProfile ¶ added in v0.25.0
WithProfile sets a custom profile to use.
func WithExtraArgs ¶ added in v0.25.0
WithExtraArgs sets additional arguments to pass to the command. This will override defined ExtraArgs on whatever profile was selected.
func WithPath ¶ added in v0.25.0
WithPath sets the path for the runner (relative to the initial root). If the path tries to escape the root, it returns an error early to avoid runtime errors deeper in the stack.
func WithProfile ¶
WithProfile sets a specific profile to use.
func WithProfiles ¶ added in v0.25.0
WithProfiles adds additional profiles to the runner's profile map. This allows profiles to be available for switching even if they don't have associated rules.
func WithWatcherBatchDuration ¶ added in v0.25.0
WithWatcherBatchDuration sets the batch duration for file system events.
type Static ¶
func (*Static) ConfigureContext ¶ added in v0.25.0
func (*Static) FS ¶ added in v0.25.0
func (rg *Static) FS() (*FilteredFS, error)
func (*Static) FindProfile ¶ added in v0.25.0
func (*Static) FindProfiles ¶ added in v0.25.0
func (rg *Static) FindProfiles(_ string) ([]ProfileMatch, error)
func (*Static) GetProfiles ¶ added in v0.25.0
func (*Static) RunContext ¶ added in v0.25.0
func (*Static) RunOnEvent ¶
func (rg *Static) RunOnEvent()