lots of changes and reducing dependency imports

This commit is contained in:
Robin Olsen
2026-02-28 16:39:50 +01:00
parent 697b17e890
commit ba0115d1bc
54 changed files with 458 additions and 327 deletions

View File

@@ -26,18 +26,18 @@ func completeIssues(cmd *cobra.Command, args []string, toComplete string) ([]str
}
// GetIssueCompletions fetches issues matching the toComplete string for shell completion.
func GetIssueCompletions(ctx context.Context, toComplete string) ([]models.Issue, cobra.ShellCompDirective) {
func GetIssueCompletions(ctx context.Context, toComplete string) ([]*models.Issue, cobra.ShellCompDirective) {
app := AppFromContext(ctx)
if app == nil {
return nil, cobra.ShellCompDirectiveNoFileComp
}
issues, err := app.Issues.AllIssues(ctx)
issues, err := app.Issues.SearchIssues(ctx, "", models.IssueFilter{})
if err != nil {
return nil, cobra.ShellCompDirectiveNoFileComp
}
var completions []models.Issue
var completions []*models.Issue
for _, issue := range issues {
if strings.HasPrefix(issue.ID, toComplete) {
completions = append(completions, issue)

View File

@@ -4,8 +4,8 @@ import (
"fmt"
"strings"
"github.com/LazyBachelor/LazyPM/internal/commands"
"github.com/LazyBachelor/LazyPM/internal/models"
"github.com/LazyBachelor/LazyPM/internal/utils"
"github.com/charmbracelet/huh"
"github.com/spf13/cobra"
@@ -112,7 +112,7 @@ func init() {
CreateCmd.Flags().StringVarP(&createFlags.issueType, "type", "t", "task", "Issue type(bug, feature, task)")
CreateCmd.Flags().IntVarP(&createFlags.priority, "priority", "p", 0, "Issue priority(0-4)")
CreateCmd.RegisterFlagCompletionFunc("type", commands.CompletionFunc(typeOptions))
CreateCmd.RegisterFlagCompletionFunc("status", commands.CompletionFunc(statusOptions))
CreateCmd.RegisterFlagCompletionFunc("priority", commands.CompletionFunc(priorityRange))
CreateCmd.RegisterFlagCompletionFunc("type", utils.CompletionFunc(typeOptions))
CreateCmd.RegisterFlagCompletionFunc("status", utils.CompletionFunc(statusOptions))
CreateCmd.RegisterFlagCompletionFunc("priority", utils.CompletionFunc(priorityRange))
}

View File

@@ -3,8 +3,8 @@ package issuesCmd
import (
"strings"
"github.com/LazyBachelor/LazyPM/internal/commands"
"github.com/LazyBachelor/LazyPM/internal/models"
"github.com/LazyBachelor/LazyPM/internal/utils"
"github.com/spf13/cobra"
)
@@ -79,7 +79,7 @@ func init() {
ListCmd.Flags().IntVarP(&listFlags.limit, "limit", "l", 25, "Limit the number of issues returned")
ListCmd.RegisterFlagCompletionFunc("status", commands.CompletionFunc(statusOptions))
ListCmd.RegisterFlagCompletionFunc("type", commands.CompletionFunc(typeOptions))
ListCmd.RegisterFlagCompletionFunc("priority", commands.CompletionFunc(priorityRange))
ListCmd.RegisterFlagCompletionFunc("status", utils.CompletionFunc(statusOptions))
ListCmd.RegisterFlagCompletionFunc("type", utils.CompletionFunc(typeOptions))
ListCmd.RegisterFlagCompletionFunc("priority", utils.CompletionFunc(priorityRange))
}

View File

@@ -4,7 +4,7 @@ import (
"bytes"
"context"
"github.com/LazyBachelor/LazyPM/internal/service"
"github.com/LazyBachelor/LazyPM/internal/models"
"github.com/charmbracelet/fang"
"github.com/spf13/cobra"
@@ -14,8 +14,9 @@ type contextKey string
const appKey contextKey = "app"
// app is a package-level variable used during command setup
var app *service.App
type App = models.App
var app *App
// Flags struct to hold command-line flag values for issues.
type Flags struct {
@@ -44,14 +45,14 @@ var RootCmd = &cobra.Command{
// SetApp sets the app variable for use in command execution.
// Must be called before executing any commands to ensure services are available.
func SetApp(application *service.App) {
func SetApp(application *App) {
app = application
RootCmd.Use = app.Config.RootCmd
}
// AppFromContext retrieves the App from the command context
func AppFromContext(ctx context.Context) *service.App {
if a, ok := ctx.Value(appKey).(*service.App); ok {
func AppFromContext(ctx context.Context) *App {
if a, ok := ctx.Value(appKey).(*App); ok {
return a
}
// Fallback to package-level app (for testing or edge cases)

View File

@@ -3,8 +3,8 @@ package issuesCmd
import (
"fmt"
"github.com/LazyBachelor/LazyPM/internal/commands"
"github.com/LazyBachelor/LazyPM/internal/models"
"github.com/LazyBachelor/LazyPM/internal/utils"
"github.com/spf13/cobra"
)
@@ -62,9 +62,9 @@ func init() {
UpdateCmd.Flags().StringVarP(&updateFlags.issueType, "type", "t", "", "New issue type(bug, feature, task)")
UpdateCmd.Flags().IntVarP(&updateFlags.priority, "priority", "p", 0, "New issue priority(0-5)")
UpdateCmd.RegisterFlagCompletionFunc("type", commands.CompletionFunc(typeOptions))
UpdateCmd.RegisterFlagCompletionFunc("status", commands.CompletionFunc(statusOptions))
UpdateCmd.RegisterFlagCompletionFunc("priority", commands.CompletionFunc(priorityRange))
UpdateCmd.RegisterFlagCompletionFunc("type", utils.CompletionFunc(typeOptions))
UpdateCmd.RegisterFlagCompletionFunc("status", utils.CompletionFunc(statusOptions))
UpdateCmd.RegisterFlagCompletionFunc("priority", utils.CompletionFunc(priorityRange))
}
func getUpdateValues(cmd *cobra.Command) (map[string]interface{}, error) {

View File

@@ -3,10 +3,14 @@ package surveyCmd
import (
"context"
"github.com/LazyBachelor/LazyPM/internal/service"
"github.com/LazyBachelor/LazyPM/internal/models"
"github.com/spf13/cobra"
)
type App = models.App
var app *App
const appKey string = "app"
const long string = `Project Management Interface Survey
@@ -18,8 +22,6 @@ This survey will present you with a series of tasks to complete using various in
Please answer the questions honestly and to the best of your ability.
Your responses will be kept confidential and used solely for research purposes.`
var app *service.App
// RootCmd is the base command for the survey CLI.
var RootCmd = &cobra.Command{
Use: "survey",
@@ -31,12 +33,12 @@ var RootCmd = &cobra.Command{
},
}
func SetApp(application *service.App) {
func SetApp(application *App) {
app = application
}
func AppFromContext(ctx context.Context) *service.App {
if a, ok := ctx.Value(appKey).(*service.App); ok {
func AppFromContext(ctx context.Context) *App {
if a, ok := ctx.Value(appKey).(*App); ok {
return a
}
return app

View File

@@ -1,7 +1,7 @@
package surveyCmd
import (
"github.com/LazyBachelor/LazyPM/internal/commands"
"github.com/LazyBachelor/LazyPM/internal/utils"
"github.com/LazyBachelor/LazyPM/pkg/task"
"github.com/spf13/cobra"
)
@@ -20,6 +20,6 @@ var StartCmd = &cobra.Command{
func init() {
StartCmd.Flags().StringVarP(&Task, "task", "t", "", "Specify task.")
StartCmd.Flags().StringVarP(&InterfaceType, "interface", "i", "", "Specify interface.")
StartCmd.RegisterFlagCompletionFunc("task", commands.CompletionFunc(task.ListTasks()))
StartCmd.RegisterFlagCompletionFunc("interface", commands.CompletionFunc(task.ListInterfaces()))
StartCmd.RegisterFlagCompletionFunc("task", utils.CompletionFunc(task.ListTasks()))
StartCmd.RegisterFlagCompletionFunc("interface", utils.CompletionFunc(task.ListInterfaces()))
}

View File

@@ -1,10 +0,0 @@
package commands
import "github.com/spf13/cobra"
// completionFunc returns a function that provides shell completion for the given options.
func CompletionFunc(options []string) func(*cobra.Command, []string, string) ([]string, cobra.ShellCompDirective) {
return func(_ *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective) {
return options, cobra.ShellCompDirectiveDefault
}
}