-
Notifications
You must be signed in to change notification settings - Fork 0
/
root.go
54 lines (45 loc) · 1.5 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
/*
Copyright © 2022 Daniils Petrovs <daniils@platogo.com>
*/
package cmd
import (
"fmt"
"os"
"path/filepath"
"github.com/platogo/cache"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
const Version = "0.3.3"
// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "zube",
Short: "A Command Line utility for interacting with Zube.io",
Long: `Zube-CLI is a CLI tool built in Go that allows you to manage Zube cards, projects and other resources from the terminal.`,
Version: Version,
}
// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
err := rootCmd.Execute()
if err != nil {
os.Exit(1)
}
}
func init() {
// rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.zube-cli.yaml)")
defaultConfigPath := filepath.Join("$HOME", "config", "zube")
xdgConfigPath := filepath.Join("$XDG_CONFIG_HOME", "zube")
viper.SetConfigName("config")
viper.SetConfigType("yaml")
viper.AddConfigPath(defaultConfigPath)
viper.AddConfigPath(xdgConfigPath)
err := viper.ReadInConfig()
if err != nil { // Handle errors reading the config file
panic(fmt.Errorf("Fatal error config file: %w \n", err))
}
cache.Init()
// Cobra also supports local flags, which will only run
// when this action is called directly.
rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}