Added cache path flag

This commit is contained in:
David Allen 2024-03-03 18:21:06 -07:00
parent 92f624239d
commit f2e5720aaa
No known key found for this signature in database
GPG key ID: 1D2A29322FBB6FCB

View file

@ -10,8 +10,8 @@ import (
) )
var ( var (
configPath = "" confPath = ""
config opaal.Config config opaal.Config
) )
var rootCmd = &cobra.Command{ var rootCmd = &cobra.Command{
Use: "opaal", Use: "opaal",
@ -30,18 +30,19 @@ func Execute() {
func init() { func init() {
cobra.OnInitialize(initConfig) cobra.OnInitialize(initConfig)
rootCmd.PersistentFlags().StringVar(&configPath, "config", "", "set the config path") rootCmd.PersistentFlags().StringVar(&confPath, "config", "", "set the config path")
rootCmd.PersistentFlags().StringVar(&config.Options.CachePath, "cache", "", "set the cache path")
} }
func initConfig() { func initConfig() {
// load config if found or create a new one // load config if found or create a new one
if configPath != "" { if confPath != "" {
exists, err := pathx.PathExists(configPath) exists, err := pathx.PathExists(confPath)
if err != nil { if err != nil {
fmt.Printf("failed to load config") fmt.Printf("failed to load config")
os.Exit(1) os.Exit(1)
} else if exists { } else if exists {
config = opaal.LoadConfig(configPath) config = opaal.LoadConfig(confPath)
} else { } else {
config = opaal.NewConfig() config = opaal.NewConfig()
} }