mirror of
https://github.com/davidallendj/opaal.git
synced 2025-12-20 03:27:02 -07:00
Fixed how config file worked
This commit is contained in:
parent
98b27bab28
commit
747ca162ed
2 changed files with 23 additions and 14 deletions
17
cmd/root.go
17
cmd/root.go
|
|
@ -2,6 +2,7 @@ package cmd
|
|||
|
||||
import (
|
||||
opaal "davidallendj/opaal/internal"
|
||||
"davidallendj/opaal/internal/util"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
|
|
@ -20,6 +21,21 @@ var rootCmd = &cobra.Command{
|
|||
},
|
||||
}
|
||||
|
||||
func initConfig() {
|
||||
// load config if found or create a new one
|
||||
if configPath != "" {
|
||||
exists, err := util.PathExists(configPath)
|
||||
if err != nil {
|
||||
fmt.Printf("failed to load config")
|
||||
os.Exit(1)
|
||||
} else if exists {
|
||||
config = opaal.LoadConfig(configPath)
|
||||
} else {
|
||||
config = opaal.NewConfig()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func Execute() {
|
||||
if err := rootCmd.Execute(); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "failed to start CLI: %s", err)
|
||||
|
|
@ -28,5 +44,6 @@ func Execute() {
|
|||
}
|
||||
|
||||
func init() {
|
||||
cobra.OnInitialize(initConfig)
|
||||
rootCmd.PersistentFlags().StringVar(&configPath, "config", "", "set the config path")
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue