Files
console/register.go
andrey e80e292830
All checks were successful
Go Action / goaction (pull_request) Successful in 45s
move command to folder
2026-01-05 23:23:20 +03:00

36 lines
813 B
Go

package console
import (
"fmt"
"gitoa.ru/go-4devs/console/command"
"gitoa.ru/go-4devs/console/internal/registry"
)
// MustRegister register command or panic if err.
func MustRegister(cmd ...command.Command) {
err := registry.Add(cmd...)
if err != nil {
panic(err)
}
}
// Register makes a command available execute in app. If Register is called twice with the same name or if driver is nil, return error.
func Register(cmd ...command.Command) error {
if err := registry.Add(cmd...); err != nil {
return fmt.Errorf("%w", err)
}
return nil
}
// Find command by name, tries to find the best match if you give it an abbreviation of a name.
func Find(name string) (command.Command, error) {
cmd, err := registry.Find(name)
if err != nil {
return cmd, fmt.Errorf("%w", err)
}
return cmd, nil
}