New Commands: - z read - Smart file reader with auto-detection (markdown, syntax highlighting) - z sys - System overview (CPU, RAM, Disk, processes) - z find - File search with pattern/size/time filters - z search - User-friendly grep alternative - z usage - Process resource usage monitor Enhancements: - Unified help system with consistent error messages - Help on error shows usage and examples for each command - "Command not found" suggests similar commands - Directory info now detects .gitignore and shows ignored files - File handler registry for extensible file type detection - Added Italic, Dim, Underline color constants
39 lines
770 B
Go
39 lines
770 B
Go
package types
|
|
|
|
type Command struct {
|
|
Name string
|
|
Description string
|
|
Handler func(args []string) error
|
|
}
|
|
|
|
type CommandRegistry struct {
|
|
commands map[string]*Command
|
|
}
|
|
|
|
func NewCommandRegistry() *CommandRegistry {
|
|
return &CommandRegistry{
|
|
commands: make(map[string]*Command),
|
|
}
|
|
}
|
|
|
|
func (r *CommandRegistry) Register(cmd *Command) {
|
|
r.commands[cmd.Name] = cmd
|
|
}
|
|
|
|
func (r *CommandRegistry) Get(name string) (*Command, bool) {
|
|
cmd, exists := r.commands[name]
|
|
return cmd, exists
|
|
}
|
|
|
|
func (r *CommandRegistry) GetAll() []*Command {
|
|
cmds := make([]*Command, 0, len(r.commands))
|
|
for _, cmd := range r.commands {
|
|
cmds = append(cmds, cmd)
|
|
}
|
|
return cmds
|
|
}
|
|
|
|
func (r *CommandRegistry) Has(name string) bool {
|
|
_, exists := r.commands[name]
|
|
return exists
|
|
}
|