-
Notifications
You must be signed in to change notification settings - Fork 0
/
root.go
60 lines (50 loc) · 1.62 KB
/
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
48
49
50
51
52
53
54
55
56
57
58
59
60
package cmd
import (
"fmt"
"github.com/davidalpert/go-printers/v1"
"github.com/davidalpert/go-yeet/internal/cfg"
"github.com/davidalpert/go-yeet/internal/diagnostics"
"github.com/spf13/cobra"
"os"
)
// Execute builds the default root command and invokes it with os.Args
func Execute() {
s := printers.DefaultOSStreams()
// configure the logger here in the outer scope so that we can defer
// any cleanup such as writing/flushing the stream
logCleanupFn := diagnostics.ConfigureLogger(s)
defer logCleanupFn()
rootCmd := NewRootCmd(s)
rootCmd.SetArgs(os.Args[1:]) // without program
if err := rootCmd.Execute(); err != nil {
_, _ = fmt.Fprintln(s.Out, err)
os.Exit(1)
}
}
// NewRootCmd creates the 'root' command and configures it's nested children
func NewRootCmd(s printers.IOStreams) *cobra.Command {
rootCmd := &cobra.Command{
Use: "yeet",
Short: "a CLI tool for yeeting content-as-code into a knowledge base",
SilenceUsage: false,
SilenceErrors: true,
CompletionOptions: cobra.CompletionOptions{
DisableDefaultCmd: true,
DisableNoDescFlag: false,
DisableDescriptions: false,
HiddenDefaultCmd: false,
},
// Uncomment the following line if your bare application
// has an action associated with it:
// Run: func(cmd *cobra.Command, args []string) { },
// RunE: func(cmd *cobra.Command, args []string) error { },
Aliases: []string{},
}
// Register subcommands
rootCmd.AddCommand(NewCmdConfig(s))
rootCmd.AddCommand(NewCmdVersion(s))
rootCmd.PersistentFlags().StringVarP(&cfg.File, "config", "c", cfg.File, "config file to use")
return rootCmd
}
func init() {
}