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
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/LazyBachelor/LazyPM/internal/service"
|
||||
"github.com/LazyBachelor/LazyPM/pkg/cli"
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -16,7 +15,6 @@ func main() {
|
||||
}
|
||||
|
||||
if err := cli.Run(context.Background(), config); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
|
||||
os.Exit(1)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,34 +1,78 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"github.com/LazyBachelor/LazyPM/internal/models"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/LazyBachelor/LazyPM/internal/models"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var (
|
||||
createDescription string
|
||||
createStatus string
|
||||
createType string
|
||||
createPriority int
|
||||
)
|
||||
|
||||
var createCmd = &cobra.Command{
|
||||
Use: "create",
|
||||
Use: "create [title]",
|
||||
Short: "Create a new issue",
|
||||
Long: `Create a new issue with the specified details.`,
|
||||
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 {
|
||||
createTitle := args[0]
|
||||
|
||||
if createTitle == "" {
|
||||
return fmt.Errorf("issue title cannot be empty")
|
||||
}
|
||||
|
||||
issue := &models.Issue{
|
||||
Title: "test",
|
||||
Description: "This is a test issue created by the CLI.",
|
||||
Status: models.StatusOpen,
|
||||
IssueType: models.TypeBug,
|
||||
Priority: 0,
|
||||
Title: createTitle,
|
||||
Description: createDescription,
|
||||
Status: models.Status(createStatus),
|
||||
IssueType: models.IssueType(createType),
|
||||
Priority: createPriority,
|
||||
}
|
||||
|
||||
err := svc.Beads.CreateIssue(cmd.Context(), issue, "test_actor")
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error creating issue: %v\n", err)
|
||||
os.Exit(1)
|
||||
return fmt.Errorf("error creating issue: %w", err)
|
||||
}
|
||||
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
|
||||
}
|
||||
|
||||
@@ -21,4 +21,5 @@ func Execute(services *service.Services) error {
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(createCmd)
|
||||
rootCmd.CompletionOptions.DisableDefaultCmd = true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user