refactor to decouple commands form entrypoint for reusability and centralizing commands.

Increase reusability and composition
This commit is contained in:
Robin Olsen
2026-02-22 19:46:55 +01:00
parent 118e67dbf4
commit 33c8c05ae3
28 changed files with 305 additions and 282 deletions

View File

@@ -0,0 +1,47 @@
package issuesCmd
import (
"github.com/LazyBachelor/LazyPM/internal/models"
"github.com/spf13/cobra"
)
// GetCmd represents the get issue command.
var GetCmd = &cobra.Command{
Use: "describe [issue ID]",
Short: "Get issue details",
Long: `Get issue details by ID`,
ValidArgsFunction: completeIssues,
Aliases: []string{"get", "read"},
Args: cobra.ExactArgs(1),
RunE: runGetCmd,
}
// runGetCmd executes the get issue command logic,
// which retrieves and displays issue details by its ID.
func runGetCmd(cmd *cobra.Command, args []string) error {
issueID := args[0]
// Fetch the issue details using the service layer.
app := AppFromContext(cmd.Context())
issuePtr, err := app.Issues.GetIssue(cmd.Context(), issueID)
if err != nil {
return err
}
// If the issue is not found, inform the user.
if issuePtr == nil {
cmd.Printf("Issue with ID %s not found\n", issueID)
return nil
}
// Display the issue details to the user.
cmd.Println(models.IssueString(*issuePtr))
return nil
}
// init function to set up the get issue command.
func init() {
}