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

     1  package cmd
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/rsteube/carapace"
     7  	"github.com/spf13/cobra"
     8  	"github.com/zaquestion/lab/internal/action"
     9  	lab "github.com/zaquestion/lab/internal/gitlab"
    10  )
    11  
    12  var issueSubscribeCmd = &cobra.Command{
    13  	Use:              "subscribe [remote] <id>",
    14  	Aliases:          []string{},
    15  	Short:            "Subscribe to an issue",
    16  	Example:          "lab issue subscribe origin 10",
    17  	PersistentPreRun: labPersistentPreRun,
    18  	Run: func(cmd *cobra.Command, args []string) {
    19  		rn, id, err := parseArgsRemoteAndID(args)
    20  		if err != nil {
    21  			log.Fatal(err)
    22  		}
    23  
    24  		err = lab.IssueSubscribe(rn, int(id))
    25  		if err != nil {
    26  			log.Fatal(err)
    27  		}
    28  		fmt.Printf("Subscribed to issue #%d\n", id)
    29  	},
    30  }
    31  
    32  func init() {
    33  	issueCmd.AddCommand(issueSubscribeCmd)
    34  	carapace.Gen(issueSubscribeCmd).PositionalCompletion(
    35  		action.Remotes(),
    36  		action.Issues(issueList),
    37  	)
    38  }