zutils/pkg/types/registry.go
selamanapps aeae34365c feat: add zutils v0.2.0 with professional table formatting
- Add directory information with Unicode table borders
- Add network information with professional formatting
- Add version command
- Add comprehensive documentation (README.md, DEVELOPMENT.md)
- Improve table output with proper borders and alignment
- Add project structure (cmd/, pkg/ directories)
2026-05-02 00:05:44 +03:00

46 lines
1 KiB
Go

package types
// Command represents a CLI command
type Command struct {
Name string
Description string
Handler func(args []string) error
}
// CommandRegistry manages available commands
type CommandRegistry struct {
commands map[string]*Command
}
// NewCommandRegistry creates a new command registry
func NewCommandRegistry() *CommandRegistry {
return &CommandRegistry{
commands: make(map[string]*Command),
}
}
// Register adds a command to the registry
func (r *CommandRegistry) Register(cmd *Command) {
r.commands[cmd.Name] = cmd
}
// Get retrieves a command by name
func (r *CommandRegistry) Get(name string) (*Command, bool) {
cmd, exists := r.commands[name]
return cmd, exists
}
// GetAll returns all registered commands
func (r *CommandRegistry) GetAll() []*Command {
cmds := make([]*Command, 0, len(r.commands))
for _, cmd := range r.commands {
cmds = append(cmds, cmd)
}
return cmds
}
// Has checks if a command exists
func (r *CommandRegistry) Has(name string) bool {
_, exists := r.commands[name]
return exists
}