- check CHANGELOG.md ver 0.2.1-alpha
This commit is contained in:
abelith committed 2026-08-14 19:14:18 +05:00
1 parent a8f164c241
commit 9434b02422
8 files changed
+59 -7

No files matched your search

+22
View File
@@ -1,11 +1,20 @@
package cli
import (
"fmt"
"github.com/abelith/spellbook/internal/errors"
"github.com/abelith/spellbook/internal/models"
"github.com/spf13/cobra"
"strings"
)
var reservedCommands = map[string]struct{}{
"add": {},
"rm": {},
"help": {},
"completion": {},
}
func NewAddCommand(app Application) *cobra.Command {
spell := models.Spell{}
@@ -16,6 +25,14 @@ func NewAddCommand(app Application) *cobra.Command {
RunE: func(cmd *cobra.Command, args []string) error {
ctx := cmd.Context()
if len(args) < 1 {
return errors.ErrInsufficientArgs
}
if isReservedCommand(args[0]) {
return fmt.Errorf("%w: %s", errors.ErrReservedCmd, args[0])
}
spell.Spell = strings.Join(args, " ")
return app.AddSpell(ctx, spell)
},
@@ -27,3 +44,8 @@ func NewAddCommand(app Application) *cobra.Command {
return cmd
}
func isReservedCommand(cmd string) bool {
_, reserved := reservedCommands[strings.ToLower(cmd)]
return reserved
}