github.com/zaquestion/lab@v0.25.1/cmd/milestone_create.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  	gitlab "github.com/xanzy/go-gitlab"
     8  	"github.com/zaquestion/lab/internal/action"
     9  	lab "github.com/zaquestion/lab/internal/gitlab"
    10  )
    11  
    12  var milestoneCreateCmd = &cobra.Command{
    13  	Use:     "create [remote] <name>",
    14  	Aliases: []string{"add"},
    15  	Short:   "Create a new milestone",
    16  	Example: heredoc.Doc(`
    17  		lab milestone create my-milestone
    18  		lab milestone create upstream 'my title' --description 'Some Description'`),
    19  	PersistentPreRun: labPersistentPreRun,
    20  	Args:             cobra.MinimumNArgs(1),
    21  	Run: func(cmd *cobra.Command, args []string) {
    22  		rn, title, err := parseArgsRemoteAndProject(args)
    23  		if err != nil {
    24  			log.Fatal(err)
    25  		}
    26  
    27  		desc, err := cmd.Flags().GetString("description")
    28  		if err != nil {
    29  			log.Fatal(err)
    30  		}
    31  
    32  		err = lab.MilestoneCreate(rn, &gitlab.CreateMilestoneOptions{
    33  			Title:       &title,
    34  			Description: &desc,
    35  		})
    36  
    37  		if err != nil {
    38  			log.Fatal(err)
    39  		}
    40  	},
    41  }
    42  
    43  func init() {
    44  	milestoneCreateCmd.Flags().String("description", "", "description of the new milestone")
    45  	milestoneCmd.AddCommand(milestoneCreateCmd)
    46  	carapace.Gen(milestoneCreateCmd).PositionalCompletion(
    47  		action.Remotes(),
    48  		carapace.ActionCallback(func(c carapace.Context) carapace.Action {
    49  			project, _, err := parseArgsRemoteAndProject(c.Args)
    50  			if err != nil {
    51  				return carapace.ActionMessage(err.Error())
    52  			}
    53  			return action.Milestones(project, action.MilestoneOpts{Active: true})
    54  		}),
    55  	)
    56  }