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,7 +10,7 @@ import (
)
var (
configPath = ""
confPath = ""
config opaal.Config
)
var rootCmd = &cobra.Command{
@ -30,18 +30,19 @@ func Execute() {
func init() {
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() {
// load config if found or create a new one
if configPath != "" {
exists, err := pathx.PathExists(configPath)
if confPath != "" {
exists, err := pathx.PathExists(confPath)
if err != nil {
fmt.Printf("failed to load config")
os.Exit(1)
} else if exists {
config = opaal.LoadConfig(configPath)
config = opaal.LoadConfig(confPath)
} else {
config = opaal.NewConfig()
}