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

     1  package cmd
     2  
     3  import (
     4  	"fmt"
     5  	"github.com/MakeNowJust/heredoc/v2"
     6  
     7  	"github.com/rsteube/carapace"
     8  	"github.com/spf13/cobra"
     9  	"github.com/zaquestion/lab/internal/action"
    10  	lab "github.com/zaquestion/lab/internal/gitlab"
    11  )
    12  
    13  var mrSubscribeCmd = &cobra.Command{
    14  	Use:     "subscribe [remote] [<MR id or branch>]",
    15  	Aliases: []string{},
    16  	Short:   "Subscribe to merge request",
    17  	Example: heredoc.Doc(`
    18  		lab mr subscribe 11
    19  		lab mr subscribe origin 12`),
    20  	PersistentPreRun: labPersistentPreRun,
    21  	Run: func(cmd *cobra.Command, args []string) {
    22  		rn, id, err := parseArgsWithGitBranchMR(args)
    23  		if err != nil {
    24  			log.Fatal(err)
    25  		}
    26  
    27  		err = lab.MRSubscribe(rn, int(id))
    28  		if err != nil {
    29  			log.Fatal(err)
    30  		}
    31  		fmt.Printf("Subscribed to merge request !%d\n", id)
    32  	},
    33  }
    34  
    35  func init() {
    36  	mrCmd.AddCommand(mrSubscribeCmd)
    37  	carapace.Gen(mrSubscribeCmd).PositionalCompletion(
    38  		action.Remotes(),
    39  		action.MergeRequests(mrList),
    40  	)
    41  }