- 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

+8
View File
@@ -2,6 +2,14 @@
## [Latest] ## [Latest]
## [0.2.1-alpha]- 2026-8-14
### Fixed
- Prevented creating spells with reserved names
- Improved error messages
## [Unreleased]
## [0.2.0-alpha] - 2026-08-08 ## [0.2.0-alpha] - 2026-08-08
### Added ### Added
+3 -2
View File
@@ -1,4 +1,4 @@
# spellbook 0.1.0-alpha # spellbook 0.2.1-alpha
`spellbook` is a lightweight CLI command manager written in Go. It allows you to save complex shell commands as parameterized templates ("spells") and execute them instantly with custom arguments. `spellbook` is a lightweight CLI command manager written in Go. It allows you to save complex shell commands as parameterized templates ("spells") and execute them instantly with custom arguments.
@@ -106,4 +106,5 @@ spellbook my-spell target=127.0.0.1
--- ---
## Upcoming Features ## Upcoming Features
- Search to navigate your spell book - Search to navigate your spell book
- Export/import spellbooks
+3 -1
View File
@@ -43,5 +43,7 @@ func main() {
c := cli.NewCLI(app) c := cli.NewCLI(app)
handleErr(c.Run(ctx)) if err := c.Run(ctx); err != nil {
os.Exit(1)
}
} }
+2 -1
View File
@@ -5,6 +5,7 @@ import (
"context" "context"
"errors" "errors"
"fmt" "fmt"
errors2 "github.com/abelith/spellbook/internal/errors"
"github.com/abelith/spellbook/internal/models" "github.com/abelith/spellbook/internal/models"
"github.com/google/shlex" "github.com/google/shlex"
"os/exec" "os/exec"
@@ -40,7 +41,7 @@ func (sc *SpellCaster) Cast(ctx context.Context, cast models.SpellCast) (models.
res.Err = err res.Err = err
return res, nil return res, nil
} }
return res, fmt.Errorf("failed to cast spell: %w", err) return res, fmt.Errorf("%w: %w", errors2.ErrFailedToCast, err)
} }
res.ExitCode = 0 res.ExitCode = 0
+2 -2
View File
@@ -3,7 +3,7 @@ package sqlite
import ( import (
"context" "context"
"database/sql" "database/sql"
"fmt" "github.com/abelith/spellbook/internal/errors"
"github.com/abelith/spellbook/internal/models" "github.com/abelith/spellbook/internal/models"
"strings" "strings"
) )
@@ -33,7 +33,7 @@ func NewRepo(db *sql.DB) *Repo {
func (r *Repo) Init(ctx context.Context) error { func (r *Repo) Init(ctx context.Context) error {
if r.db == nil { if r.db == nil {
return fmt.Errorf("no db provided") return errors.ErrNoDBProvided
} }
if _, err := r.db.ExecContext(ctx, schema); err != nil { if _, err := r.db.ExecContext(ctx, schema); err != nil {
+22
View File
@@ -1,11 +1,20 @@
package cli package cli
import ( import (
"fmt"
"github.com/abelith/spellbook/internal/errors"
"github.com/abelith/spellbook/internal/models" "github.com/abelith/spellbook/internal/models"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"strings" "strings"
) )
var reservedCommands = map[string]struct{}{
"add": {},
"rm": {},
"help": {},
"completion": {},
}
func NewAddCommand(app Application) *cobra.Command { func NewAddCommand(app Application) *cobra.Command {
spell := models.Spell{} spell := models.Spell{}
@@ -16,6 +25,14 @@ func NewAddCommand(app Application) *cobra.Command {
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
ctx := cmd.Context() 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, " ") spell.Spell = strings.Join(args, " ")
return app.AddSpell(ctx, spell) return app.AddSpell(ctx, spell)
}, },
@@ -27,3 +44,8 @@ func NewAddCommand(app Application) *cobra.Command {
return cmd return cmd
} }
func isReservedCommand(cmd string) bool {
_, reserved := reservedCommands[strings.ToLower(cmd)]
return reserved
}
+9 -1
View File
@@ -1,6 +1,10 @@
package cli package cli
import "github.com/spf13/cobra" import (
"fmt"
"github.com/abelith/spellbook/internal/errors"
"github.com/spf13/cobra"
)
func NewRmCommand(app Application) *cobra.Command { func NewRmCommand(app Application) *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
@@ -10,6 +14,10 @@ func NewRmCommand(app Application) *cobra.Command {
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
ctx := cmd.Context() ctx := cmd.Context()
if len(args) < 1 {
return fmt.Errorf("%w: %s", errors.ErrInsufficientArgs, "spell_name")
}
return app.DeleteSpell(ctx, args[0]) return app.DeleteSpell(ctx, args[0])
}, },
} }
+10
View File
@@ -0,0 +1,10 @@
package errors
import "fmt"
var (
ErrReservedCmd = fmt.Errorf("command name is reserved")
ErrInsufficientArgs = fmt.Errorf("mandatory args are missing")
ErrFailedToCast = fmt.Errorf("failed to cast spell")
ErrNoDBProvided = fmt.Errorf("no db provided")
)