From 281d7d76d4abebadadce90b6f802b0916665f444 Mon Sep 17 00:00:00 2001 From: Kirillkriv Date: Sat, 8 Aug 2026 17:18:34 +0500 Subject: [PATCH] chore - minor refactor --- cmd/main.go | 10 +++----- internal/{ => controllers}/cli/add.go | 0 internal/controllers/cli/cli.go | 35 ++++++++++++++++++++++++++ internal/{ => controllers}/cli/rm.go | 0 internal/{ => controllers}/cli/root.go | 8 ------ 5 files changed, 38 insertions(+), 15 deletions(-) rename internal/{ => controllers}/cli/add.go (100%) create mode 100644 internal/controllers/cli/cli.go rename internal/{ => controllers}/cli/rm.go (100%) rename internal/{ => controllers}/cli/root.go (84%) diff --git a/cmd/main.go b/cmd/main.go index b5f88f5..a622ab5 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -7,7 +7,7 @@ import ( "github.com/abelith/spellbook/internal/adapters/caster" "github.com/abelith/spellbook/internal/adapters/sqlite" "github.com/abelith/spellbook/internal/application" - "github.com/abelith/spellbook/internal/cli" + "github.com/abelith/spellbook/internal/controllers/cli" _ "modernc.org/sqlite" "os" "os/signal" @@ -33,11 +33,7 @@ func main() { app := application.NewApplication(&caster.SpellCaster{}, repo, repo) - root := cli.NewRootCmd(app) - root.AddCommand( - cli.NewAddCommand(app), - cli.NewRmCommand(app), - ) + c := cli.NewCLI(app) - handleErr(root.Execute()) + handleErr(c.Run(ctx)) } diff --git a/internal/cli/add.go b/internal/controllers/cli/add.go similarity index 100% rename from internal/cli/add.go rename to internal/controllers/cli/add.go diff --git a/internal/controllers/cli/cli.go b/internal/controllers/cli/cli.go new file mode 100644 index 0000000..8c4cfe6 --- /dev/null +++ b/internal/controllers/cli/cli.go @@ -0,0 +1,35 @@ +package cli + +import ( + "context" + "github.com/abelith/spellbook/internal/models" + "github.com/spf13/cobra" +) + +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) +} + +type CLI struct { + root *cobra.Command +} + +func NewCLI(app Application) *CLI { + root := NewRootCmd(app) + root.AddCommand( + NewAddCommand(app), + NewRmCommand(app), + ) + + return &CLI{ + root: root, + } +} + +func (c *CLI) Run(_ context.Context) error { + return c.root.Execute() +} diff --git a/internal/cli/rm.go b/internal/controllers/cli/rm.go similarity index 100% rename from internal/cli/rm.go rename to internal/controllers/cli/rm.go diff --git a/internal/cli/root.go b/internal/controllers/cli/root.go similarity index 84% rename from internal/cli/root.go rename to internal/controllers/cli/root.go index 05ffa87..7e49db0 100644 --- a/internal/cli/root.go +++ b/internal/controllers/cli/root.go @@ -9,14 +9,6 @@ import ( "strings" ) -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) -} - func rootCmd(app Application) func(*cobra.Command, []string) error { return func(cmd *cobra.Command, args []string) error { ctx := cmd.Context()