use cobra for cli

delete pkg/runner and put funcs in task
add start command
This commit is contained in:
Robin Olsen
2026-02-17 10:24:15 +01:00
parent d5daa49b64
commit a38e32aa78
5 changed files with 101 additions and 73 deletions

48
cmd/survey/cmd.go Normal file
View File

@@ -0,0 +1,48 @@
package main
import (
"errors"
"log"
"os"
"github.com/LazyBachelor/LazyPM/pkg/task"
"github.com/spf13/cobra"
)
var rootCmd = &cobra.Command{
Use: "survey",
Short: "Run the user survey",
}
var startCmd = &cobra.Command{
Use: "start",
Short: "Start the user survey",
Run: func(cmd *cobra.Command, args []string) {
if err := newIntroModel().Run(); err != nil {
if errors.Is(err, ErrUserQuit) {
os.Exit(0)
}
log.Fatalf("Failed to run intro screen: %v\n", err)
}
svc, close, err := initializeServices(cmd.Context())
if err != nil {
log.Fatalf("Failed to initialize services: %v\n", err)
}
defer close()
surveyTasks := initTasks()
interfaces := initInterfaces()
if err := taskLoop(cmd.Context(), svc, surveyTasks, interfaces); err != nil {
if errors.Is(err, task.ErrUserQuit) {
os.Exit(0)
}
log.Fatalf("Task loop failed: %v\n", err)
}
},
}
func init() {
rootCmd.AddCommand(startCmd)
}

17
cmd/survey/main.go Normal file
View File

@@ -0,0 +1,17 @@
package main
import (
"context"
"log"
"github.com/charmbracelet/fang"
)
func main() {
ctx := context.Background()
if err := fang.Execute(ctx, rootCmd,
fang.WithColorSchemeFunc(fang.AnsiColorScheme)); err != nil {
log.Fatalf("Failed to execute command: %v\n", err)
}
}

View File

@@ -4,41 +4,12 @@ import (
"context"
"errors"
"fmt"
"log"
"math/rand"
"os"
"github.com/LazyBachelor/LazyPM/internal/service"
"github.com/LazyBachelor/LazyPM/pkg/task"
)
func main() {
ctx := context.Background()
if err := newIntroModel().Run(); err != nil {
if errors.Is(err, ErrUserQuit) {
os.Exit(0)
}
log.Fatalf("Failed to run intro screen: %v\n", err)
}
svc, close, err := initializeServices(ctx)
if err != nil {
log.Fatalf("Failed to initialize services: %v\n", err)
}
defer close()
surveyTasks := initTasks()
interfaces := initInterfaces()
if err := taskLoop(ctx, svc, surveyTasks, interfaces); err != nil {
if errors.Is(err, task.ErrUserQuit) {
os.Exit(0)
}
log.Fatalf("Task loop failed: %v\n", err)
}
}
func taskLoop(ctx context.Context, svc *service.Services, surveyTasks []*task.Task, interfaces []task.Interface) error {
interfaceIndex := rand.Int() % len(interfaces)