improved: make haunt run generate default config if none found
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
parent
0e454d971d
commit
4e854075df
16
cmd/run.go
16
cmd/run.go
@ -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,7 +47,19 @@ 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 {
|
||||||
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 {
|
if len(args) >= 1 {
|
||||||
// filter by name flag if exist
|
// filter by name flag if exist
|
||||||
|
Loading…
Reference in New Issue
Block a user