Files
spellbook/internal/controllers/cli/cli.go
T
2026-08-21 15:52:26 +05:00

42 lines
989 B
Go

package cli
import (
"context"
"github.com/abelith/spellbook/internal/models"
"github.com/spf13/cobra"
"io"
)
type Application interface {
AddSpell(ctx context.Context, spell models.Spell) error
GetSpell(ctx context.Context, spellName string) (models.Spell, error)
GetSpells(ctx context.Context, query models.SearchQuery) ([]models.Spell, error)
DeleteSpell(ctx context.Context, spellName string) error
CastSpell(ctx context.Context, spellCast models.SpellCast) (models.CastResult, error)
ExportSpells(ctx context.Context, exp string, w io.Writer) error
ImportSpells(ctx context.Context, exp string, r io.Reader) error
}
type CLI struct {
root *cobra.Command
}
func NewCLI(ver string, app Application) *CLI {
root := NewRootCmd(ver, app)
root.AddCommand(
NewAddCommand(app),
NewRmCommand(app),
NewSearchCmd(app),
NewExportCmd(app),
NewImportCmd(app),
)
return &CLI{
root: root,
}
}
func (c *CLI) Run(_ context.Context) error {
return c.root.Execute()
}