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

     1  package cmd
     2  
     3  import (
     4  	"github.com/rsteube/carapace"
     5  	"github.com/spf13/cobra"
     6  	"github.com/zaquestion/lab/internal/action"
     7  	lab "github.com/zaquestion/lab/internal/gitlab"
     8  )
     9  
    10  var milestoneDeleteCmd = &cobra.Command{
    11  	Use:              "delete [remote] <name>",
    12  	Aliases:          []string{"remove"},
    13  	Short:            "Deletes an existing milestone",
    14  	Example:          "lab label delete origin 'some milestone'",
    15  	PersistentPreRun: labPersistentPreRun,
    16  	Args:             cobra.MinimumNArgs(1),
    17  	Run: func(cmd *cobra.Command, args []string) {
    18  		rn, name, err := parseArgsRemoteAndProject(args)
    19  		if err != nil {
    20  			log.Fatal(err)
    21  		}
    22  
    23  		err = lab.MilestoneDelete(rn, name)
    24  		if err != nil {
    25  			log.Fatal(err)
    26  		}
    27  	},
    28  }
    29  
    30  func init() {
    31  	milestoneCmd.AddCommand(milestoneDeleteCmd)
    32  	carapace.Gen(milestoneDeleteCmd).PositionalCompletion(
    33  		action.Remotes(),
    34  		carapace.ActionCallback(func(c carapace.Context) carapace.Action {
    35  			project, _, err := parseArgsRemoteAndProject(c.Args)
    36  			if err != nil {
    37  				return carapace.ActionMessage(err.Error())
    38  			}
    39  			return action.Milestones(project, action.MilestoneOpts{Active: true})
    40  		}),
    41  	)
    42  }