adding delete command in the file pkg/cli/commands/delete.go
This commit is contained in:
47
pkg/cli/commands/delete.go
Normal file
47
pkg/cli/commands/delete.go
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
package commands
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/LazyBachelor/LazyPM/internal/models"
|
||||||
|
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
var deleteCmd = &cobra.Command{
|
||||||
|
Use: "delete [id]",
|
||||||
|
Short: "Delete existing issue",
|
||||||
|
Long: `Delete an existing issue by its ID.`,
|
||||||
|
Example: `pm delete issue_id`,
|
||||||
|
RunE: runDeleteCmd,
|
||||||
|
Aliases: []string{"del"},
|
||||||
|
Args: cobra.MinimumNArgs(1),
|
||||||
|
}
|
||||||
|
|
||||||
|
func runDeleteCmd(cmd *cobra.Command, args []string) error {
|
||||||
|
deleteID := strings.Join(args, " ")
|
||||||
|
|
||||||
|
if deleteID == "" {
|
||||||
|
return fmt.Errorf("issue title cannot be empty")
|
||||||
|
}
|
||||||
|
|
||||||
|
issue := &models.Issue{
|
||||||
|
ID: deleteID,
|
||||||
|
}
|
||||||
|
|
||||||
|
err := svc.Beads.DeleteIssue(cmd.Context(), issue.ID)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error deleting issue: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
str := fmt.Sprintf("Deleted issue with ID: %s\n", issue.ID)
|
||||||
|
|
||||||
|
if issue.Title != "" {
|
||||||
|
str += fmt.Sprintf("Title: %s\n", issue.Title)
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Print(str)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -30,7 +30,7 @@ func ExecuteWithArgs(args []string) error {
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
rootCmd.AddCommand(createCmd)
|
rootCmd.AddCommand(createCmd)
|
||||||
|
rootCmd.AddCommand(deleteCmd)
|
||||||
rootCmd.CompletionOptions.DisableDefaultCmd = false
|
rootCmd.CompletionOptions.DisableDefaultCmd = false
|
||||||
rootCmd.AddGroup(&cobra.Group{ID: "help", Title: "Helping Commands"})
|
rootCmd.AddGroup(&cobra.Group{ID: "help", Title: "Helping Commands"})
|
||||||
rootCmd.SetCompletionCommandGroupID("help")
|
rootCmd.SetCompletionCommandGroupID("help")
|
||||||
|
|||||||
Reference in New Issue
Block a user