github.com/nkprince007/lab@v0.6.2-0.20171218071646-19d68b56f403/cmd/snippet.go (about) 1 package cmd 2 3 import ( 4 "github.com/spf13/cobra" 5 ) 6 7 // snippetCmd represents the snippet command 8 var snippetCmd = &cobra.Command{ 9 Use: "snippet", 10 Aliases: []string{"snip"}, 11 Short: snippetCreateCmd.Short, 12 Long: snippetCreateCmd.Long, 13 Run: func(cmd *cobra.Command, args []string) { 14 if list, _ := cmd.Flags().GetBool("list"); list { 15 snippetListCmd.Run(cmd, args) 16 return 17 } 18 19 if deleteID, _ := cmd.Flags().GetInt("delete"); deleteID != 0 { 20 // append the args here so that remote can stil be 21 // properly passed in 22 snippetDeleteCmd.Run(cmd, append(args, string(deleteID))) 23 return 24 } 25 if len(args) == 0 && file == "" { 26 cmd.Help() 27 return 28 } 29 snippetCreateCmd.Run(cmd, args) 30 }, 31 } 32 33 var ( 34 global bool 35 ) 36 37 func init() { 38 snippetCmd.PersistentFlags().BoolVarP(&global, "global", "g", false, "create as a personal snippet") 39 snippetCmd.Flags().BoolP("list", "l", false, "list snippets") 40 snippetCmd.Flags().IntP("delete", "d", 0, "delete snippet with id") 41 // Create flags added in snippetCreate.go 42 RootCmd.AddCommand(snippetCmd) 43 }