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

This commit is contained in:
abs3nt 2023-03-06 11:02:34 -08:00
parent 0e454d971d
commit 4e854075df
1 changed files with 15 additions and 1 deletions

View File

@ -1,7 +1,9 @@
package cmd
import (
"fmt"
"log"
"os"
"strings"
"github.com/abs3ntdev/haunt/src/haunt"
@ -45,7 +47,19 @@ func run(cmd *cobra.Command, args []string) (err error) {
// read a config if exist
err = h.Settings.Read(&h)
if err != nil {
return err
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
}
}
if len(args) >= 1 {
// filter by name flag if exist