refactor to use app package instead of service
refactor app to be composable
This commit is contained in:
@@ -4,14 +4,14 @@ package cli
|
||||
import (
|
||||
"context"
|
||||
|
||||
issuesCmd "github.com/LazyBachelor/LazyPM/internal/commands/issues"
|
||||
"github.com/LazyBachelor/LazyPM/internal/app"
|
||||
issues "github.com/LazyBachelor/LazyPM/internal/commands/issues"
|
||||
"github.com/LazyBachelor/LazyPM/internal/models"
|
||||
"github.com/LazyBachelor/LazyPM/internal/service"
|
||||
"github.com/charmbracelet/fang"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// Config is an alias for service.Config, used to configure the CLI.
|
||||
// Config is an alias for app.Config, used to configure the CLI.
|
||||
type Config = models.Config
|
||||
|
||||
type CLI struct {
|
||||
@@ -26,14 +26,14 @@ func New(rootCmd *cobra.Command) *CLI {
|
||||
|
||||
// Run initializes the services and executes the CLI commands.
|
||||
func (c *CLI) Run(ctx context.Context, config Config) error {
|
||||
app, cleanup, err := service.NewApp(ctx, config)
|
||||
app, cleanup, err := app.New(ctx, config)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
defer cleanup()
|
||||
|
||||
issuesCmd.SetApp(app)
|
||||
issues.SetApp(app)
|
||||
|
||||
if err := fang.Execute(ctx, c.RootCmd,
|
||||
fang.WithColorSchemeFunc(fang.AnsiColorScheme)); err != nil {
|
||||
@@ -45,16 +45,16 @@ func (c *CLI) Run(ctx context.Context, config Config) error {
|
||||
|
||||
// RunWithArgs initializes the services and executes the CLI commands with the provided arguments.
|
||||
func (c *CLI) RunWithArgs(ctx context.Context, config Config, args []string) error {
|
||||
app, cleanup, err := service.NewApp(ctx, config)
|
||||
app, cleanup, err := app.New(ctx, config)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
defer cleanup()
|
||||
|
||||
issuesCmd.SetApp(app)
|
||||
issues.SetApp(app)
|
||||
|
||||
if err := issuesCmd.ExecuteArgs(args); err != nil {
|
||||
if err := issues.ExecuteArgs(args); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user