chore
- minor refactor
This commit is contained in:
1 parent
7f85815839
commit
281d7d76d4
5 files changed
+38
-15
No files matched your search
+3
-7
@@ -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))
|
||||
}
|
||||
File renamed without changes.
@@ -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()
|
||||
}
|
||||
File renamed without changes.
@@ -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()
|
||||
Reference in new issue
Block a user