Merge pull request #1 from LazyBachelor/LPM-28
Added title and description for CREATE ISSUE CLI Added other flags to create command and validation
This commit is contained in:
@@ -1,11 +1,10 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
"github.com/LazyBachelor/LazyPM/internal/service"
|
"github.com/LazyBachelor/LazyPM/internal/service"
|
||||||
"github.com/LazyBachelor/LazyPM/pkg/cli"
|
"github.com/LazyBachelor/LazyPM/pkg/cli"
|
||||||
"context"
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@@ -16,7 +15,6 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err := cli.Run(context.Background(), config); err != nil {
|
if err := cli.Run(context.Background(), config); err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
|
return
|
||||||
os.Exit(1)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,34 +1,78 @@
|
|||||||
package commands
|
package commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/LazyBachelor/LazyPM/internal/models"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
|
||||||
|
"github.com/LazyBachelor/LazyPM/internal/models"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
createDescription string
|
||||||
|
createStatus string
|
||||||
|
createType string
|
||||||
|
createPriority int
|
||||||
|
)
|
||||||
|
|
||||||
var createCmd = &cobra.Command{
|
var createCmd = &cobra.Command{
|
||||||
Use: "create",
|
Use: "create [title]",
|
||||||
Short: "Create a new issue",
|
Short: "Create a new issue",
|
||||||
Long: `Create a new issue with the specified details.`,
|
Long: `Create a new issue with the specified details.`,
|
||||||
RunE: runCreateCmd,
|
RunE: runCreateCmd,
|
||||||
|
Args: cobra.ExactArgs(1),
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
createCmd.Flags().StringVarP(&createDescription, "desc", "d", "", "Issue description")
|
||||||
|
createCmd.Flags().StringVarP(&createStatus, "status", "s", "open", "Issue status(open, closed, in_progress)")
|
||||||
|
createCmd.Flags().StringVarP(&createType, "type", "t", "task", "Issue type(bug, feature, task)")
|
||||||
|
createCmd.Flags().IntVarP(&createPriority, "priority", "p", 0, "Issue priority(0-5)")
|
||||||
}
|
}
|
||||||
|
|
||||||
func runCreateCmd(cmd *cobra.Command, args []string) error {
|
func runCreateCmd(cmd *cobra.Command, args []string) error {
|
||||||
|
createTitle := args[0]
|
||||||
|
|
||||||
|
if createTitle == "" {
|
||||||
|
return fmt.Errorf("issue title cannot be empty")
|
||||||
|
}
|
||||||
|
|
||||||
issue := &models.Issue{
|
issue := &models.Issue{
|
||||||
Title: "test",
|
Title: createTitle,
|
||||||
Description: "This is a test issue created by the CLI.",
|
Description: createDescription,
|
||||||
Status: models.StatusOpen,
|
Status: models.Status(createStatus),
|
||||||
IssueType: models.TypeBug,
|
IssueType: models.IssueType(createType),
|
||||||
Priority: 0,
|
Priority: createPriority,
|
||||||
}
|
}
|
||||||
|
|
||||||
err := svc.Beads.CreateIssue(cmd.Context(), issue, "test_actor")
|
err := svc.Beads.CreateIssue(cmd.Context(), issue, "test_actor")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "Error creating issue: %v\n", err)
|
return fmt.Errorf("error creating issue: %w", err)
|
||||||
os.Exit(1)
|
|
||||||
}
|
}
|
||||||
fmt.Printf("Created issue: %s\n", issue.ID)
|
|
||||||
|
str := fmt.Sprintf("Created issue with ID: %s\n", issue.ID)
|
||||||
|
|
||||||
|
if issue.Title != "" {
|
||||||
|
str += fmt.Sprintf("Title: %s\n", issue.Title)
|
||||||
|
}
|
||||||
|
|
||||||
|
if issue.Description != "" {
|
||||||
|
str += fmt.Sprintf("Description: %s\n", issue.Description)
|
||||||
|
}
|
||||||
|
|
||||||
|
if issue.Status != "" {
|
||||||
|
str += fmt.Sprintf("Status: %s\n", issue.Status)
|
||||||
|
}
|
||||||
|
|
||||||
|
if issue.IssueType != "" {
|
||||||
|
str += fmt.Sprintf("Type: %s\n", issue.IssueType)
|
||||||
|
}
|
||||||
|
|
||||||
|
if issue.Priority != 0 {
|
||||||
|
str += fmt.Sprintf("Priority: %d\n", issue.Priority)
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Print(str)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,4 +21,5 @@ func Execute(services *service.Services) error {
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
rootCmd.AddCommand(createCmd)
|
rootCmd.AddCommand(createCmd)
|
||||||
|
rootCmd.CompletionOptions.DisableDefaultCmd = true
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user