Search for config.yaml/yml in both service and cli mode

This commit is contained in:
Nate Brown
2026-05-08 10:13:45 -05:00
parent 1ada3d4dd9
commit 4c51a26203
5 changed files with 110 additions and 21 deletions

View File

@@ -61,9 +61,12 @@ func main() {
}
if *configPath == "" {
fmt.Println("-config flag must be set")
flag.Usage()
os.Exit(1)
p, err := config.DefaultPath()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
*configPath = p
}
c := config.NewC(l)

View File

@@ -3,8 +3,6 @@ package main
import (
"fmt"
"log"
"os"
"path/filepath"
"github.com/kardianos/service"
"github.com/slackhq/nebula"
@@ -57,24 +55,13 @@ func (p *program) Stop(s service.Service) error {
return nil
}
func fileExists(filename string) bool {
_, err := os.Stat(filename)
if os.IsNotExist(err) {
return false
}
return true
}
func doService(configPath *string, configTest *bool, build string, serviceFlag *string) error {
if *configPath == "" {
ex, err := os.Executable()
p, err := config.DefaultPath()
if err != nil {
return err
}
*configPath = filepath.Dir(ex) + "/config.yaml"
if !fileExists(*configPath) {
*configPath = filepath.Dir(ex) + "/config.yml"
}
*configPath = p
}
svcConfig := &service.Config{

View File

@@ -50,9 +50,12 @@ func main() {
}
if *configPath == "" {
fmt.Println("-config flag must be set")
flag.Usage()
os.Exit(1)
p, err := config.DefaultPath()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
*configPath = p
}
l := logging.NewLogger(os.Stdout)