github.com/zaquestion/lab@v0.25.1/cmd/mr.go (about) 1 package cmd 2 3 import ( 4 "github.com/spf13/cobra" 5 ) 6 7 // mrCmd represents the mr command 8 var mrCmd = &cobra.Command{ 9 Use: "mr", 10 Short: `Describe, list, and create merge requests`, 11 Long: ``, 12 PersistentPreRun: labPersistentPreRun, 13 Run: func(cmd *cobra.Command, args []string) { 14 if list, _ := cmd.Flags().GetBool("list"); list { 15 listCmd.Run(cmd, args) 16 return 17 } 18 19 if browse, _ := cmd.Flags().GetBool("browse"); browse { 20 mrBrowseCmd.Run(cmd, args) 21 return 22 } 23 24 if id, _ := cmd.Flags().GetString("close"); id != "" { 25 mrCloseCmd.Run(cmd, append(args, id)) 26 return 27 } 28 29 if len(args) == 0 || len(args) > 2 { 30 cmd.Help() 31 return 32 } 33 34 mrShowCmd.Run(cmd, args) 35 }, 36 } 37 38 func init() { 39 mrCmd.Flags().BoolP("list", "l", false, "list merge requests on a remote") 40 mrCmd.Flags().MarkDeprecated("list", "use the \"list\" subcommand instead") 41 mrCmd.Flags().BoolP("browse", "b", false, "view merge request <id> in a browser") 42 mrCmd.Flags().MarkDeprecated("browse", "use the \"browse\" subcommand instead") 43 mrCmd.Flags().StringP("close", "d", "", "close merge request <id> on remote") 44 mrCmd.Flags().MarkDeprecated("close", "use the \"close\" subcommand instead") 45 RootCmd.AddCommand(mrCmd) 46 }