improved: make haunt run generate default config if none found
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
abs3nt 2023-03-06 11:02:34 -08:00
parent 0e454d971d
commit 4e854075df

View File

@ -1,7 +1,9 @@
package cmd package cmd
import ( import (
"fmt"
"log" "log"
"os"
"strings" "strings"
"github.com/abs3ntdev/haunt/src/haunt" "github.com/abs3ntdev/haunt/src/haunt"
@ -45,8 +47,20 @@ func run(cmd *cobra.Command, args []string) (err error) {
// read a config if exist // read a config if exist
err = h.Settings.Read(&h) err = h.Settings.Read(&h)
if err != nil { if err != nil {
if os.IsNotExist(err) {
log.Println(h.Prefix("No config file found, initializing one for you"))
err = defaultConfig(cmd, args)
if err != nil {
log.Println(h.Prefix("Failed to generate default config: " + err.Error()))
}
err = h.Settings.Read(&h)
if err != nil {
return fmt.Errorf(h.Prefix("Failed to read config file: " + err.Error()))
}
} else {
return err return err
} }
}
if len(args) >= 1 { if len(args) >= 1 {
// filter by name flag if exist // filter by name flag if exist
h.Projects = h.Filter(args) h.Projects = h.Filter(args)