/
root.go
47 lines (38 loc) · 974 Bytes
/
root.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
package cmd
import (
"fmt"
"github.com/spf13/cobra"
)
func newRootCmd() *cobra.Command {
rootCmd := &cobra.Command{
Use: "maildir-stats",
Short: "Report maildir statistics",
Run: func(cmd *cobra.Command, args []string) {
_ = cmd.Help()
},
SilenceErrors: true,
CompletionOptions: cobra.CompletionOptions{
HiddenDefaultCmd: true,
},
}
rootCmd.AddCommand(newVersionCmd())
rootCmd.AddCommand(newUserCmd())
rootCmd.AddCommand(newAllCmd())
rootCmd.AddCommand(newUserListCmd())
for _, c := range rootCmd.Commands() {
// フラグ以外は受け付けないように
c.Args = func(cmd *cobra.Command, args []string) error {
if len(args) > 0 {
return fmt.Errorf("only flags can be specified")
}
return nil
}
c.Flags().SortFlags = false
c.InheritedFlags().SortFlags = false
}
return rootCmd
}
func Execute() {
rootCmd := newRootCmd()
cobra.CheckErr(rootCmd.Execute())
}