add some helpers to simplify task creation
This commit is contained in:
@@ -6,14 +6,12 @@ import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
|
||||
"github.com/LazyBachelor/LazyPM/pkg/cli/repl"
|
||||
"github.com/LazyBachelor/LazyPM/cmd/survey/tasks"
|
||||
"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, InterfaceToType(i))
|
||||
return task.RunTask(ctx, t, i, tasks.InterfaceToType(i))
|
||||
}
|
||||
|
||||
func taskLoop(ctx context.Context, surveyTasks []task.Tasker, interfaces map[string]task.Interface) error {
|
||||
@@ -37,19 +35,6 @@ 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
|
||||
|
||||
Reference in New Issue
Block a user