refactor for simplicity

This commit is contained in:
Robin Olsen
2026-02-18 15:32:08 +01:00
parent 2583ca13c3
commit 612f0c86c7
3 changed files with 41 additions and 48 deletions

View File

@@ -6,12 +6,14 @@ import (
"fmt"
"math/rand"
"github.com/LazyBachelor/LazyPM/cmd/survey/tasks"
"github.com/LazyBachelor/LazyPM/pkg/cli/repl"
"github.com/LazyBachelor/LazyPM/pkg/task"
"github.com/LazyBachelor/LazyPM/pkg/tui"
"github.com/LazyBachelor/LazyPM/pkg/web"
)
func runTask(ctx context.Context, t task.Tasker, i task.Interface) error {
return task.RunTask(ctx, t, i, tasks.InterfaceToType(i))
return task.RunTask(ctx, t, i, InterfaceToType(i))
}
func taskLoop(ctx context.Context, surveyTasks []task.Tasker, interfaces map[string]task.Interface) error {
@@ -35,6 +37,19 @@ func taskLoop(ctx context.Context, surveyTasks []task.Tasker, interfaces map[str
return nil
}
func InterfaceToType(it task.Interface) task.InterfaceType {
switch it.(type) {
case *repl.REPL:
return task.InterfaceCLI
case *tui.Tui:
return task.InterfaceTUI
case *web.Web:
return task.InterfaceWeb
default:
return task.InterfaceType("unknown")
}
}
func returnIfUserQuit(err error, msg string) error {
if errors.Is(err, task.ErrUserQuit) {
return nil