github.com/zaquestion/lab@v0.25.1/cmd/label_delete.go (about)

     1  package cmd
     2  
     3  import (
     4  	"github.com/MakeNowJust/heredoc/v2"
     5  	"github.com/rsteube/carapace"
     6  	"github.com/spf13/cobra"
     7  	"github.com/zaquestion/lab/internal/action"
     8  	lab "github.com/zaquestion/lab/internal/gitlab"
     9  )
    10  
    11  var labelDeleteCmd = &cobra.Command{
    12  	Use:     "delete [remote] <name>",
    13  	Aliases: []string{"remove"},
    14  	Short:   "Deletes an existing label",
    15  	Example: heredoc.Doc(`
    16  		lab label delete my-label
    17  		lab label delete origin my-label`),
    18  	PersistentPreRun: labPersistentPreRun,
    19  	Args:             cobra.MinimumNArgs(1),
    20  	Run: func(cmd *cobra.Command, args []string) {
    21  		rn, name, err := parseArgsRemoteAndProject(args)
    22  		if err != nil {
    23  			log.Fatal(err)
    24  		}
    25  
    26  		labels, err := mapLabels(rn, []string{name})
    27  		if err != nil {
    28  			log.Fatal(err)
    29  		}
    30  
    31  		err = lab.LabelDelete(rn, labels[0])
    32  		if err != nil {
    33  			log.Fatal(err)
    34  		}
    35  	},
    36  }
    37  
    38  func init() {
    39  	labelCmd.AddCommand(labelDeleteCmd)
    40  	carapace.Gen(labelCmd).PositionalCompletion(
    41  		action.Remotes(),
    42  	)
    43  }