forked from zaquestion/lab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
snippet.go
58 lines (48 loc) · 1.34 KB
/
snippet.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package cmd
import (
"os"
"github.com/spf13/cobra"
)
// snippetCmd represents the snippet command
var snippetCmd = &cobra.Command{
Use: "snippet",
Aliases: []string{"snip"},
Short: snippetCreateCmd.Short,
Long: snippetCreateCmd.Long,
Run: func(cmd *cobra.Command, args []string) {
if list, _ := cmd.Flags().GetBool("list"); list {
snippetListCmd.Run(cmd, args)
return
}
if browse, _ := cmd.Flags().GetBool("browse"); browse {
snippetBrowseCmd.Run(cmd, args)
return
}
if deleteID, _ := cmd.Flags().GetString("delete"); deleteID != "" {
// append the args here so that remote can stil be
// properly passed in
snippetDeleteCmd.Run(cmd, append(args, deleteID))
return
}
if stat, _ := os.Stdin.Stat(); (stat.Mode() & os.ModeCharDevice) == 0 {
snippetCreateCmd.Run(cmd, args)
return
}
if len(args) > 0 || file != "" {
snippetCreateCmd.Run(cmd, args)
return
}
cmd.Help()
},
}
var (
global bool
)
func init() {
snippetCmd.PersistentFlags().BoolVarP(&global, "global", "g", false, "create as a personal snippet")
snippetCmd.Flags().BoolP("list", "l", false, "list snippets")
snippetCmd.Flags().BoolP("browse", "b", false, "browse snippets")
snippetCmd.Flags().StringP("delete", "d", "", "delete snippet with id")
// Create flags added in snippetCreate.go
RootCmd.AddCommand(snippetCmd)
}