mirror of
https://github.com/zrepl/zrepl.git
synced 2025-02-16 18:30:54 +01:00
cmd: no context + logging for config parsing
This commit is contained in:
parent
af2ff08940
commit
e87ce3f7cf
@ -3,7 +3,6 @@ package cmd
|
|||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
|
||||||
"context"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/mitchellh/mapstructure"
|
"github.com/mitchellh/mapstructure"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
@ -28,9 +27,7 @@ type ConfigParsingContext struct {
|
|||||||
Global *Global
|
Global *Global
|
||||||
}
|
}
|
||||||
|
|
||||||
func ParseConfig(ctx context.Context, path string) (config *Config, err error) {
|
func ParseConfig(path string) (config *Config, err error) {
|
||||||
|
|
||||||
log := ctx.Value(contextKeyLog).(Logger)
|
|
||||||
|
|
||||||
if path == "" {
|
if path == "" {
|
||||||
// Try default locations
|
// Try default locations
|
||||||
@ -40,7 +37,7 @@ func ParseConfig(ctx context.Context, path string) (config *Config, err error) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if !stat.Mode().IsRegular() {
|
if !stat.Mode().IsRegular() {
|
||||||
log.Printf("warning: file at default location is not a regular file: %s", l)
|
err = errors.Errorf("file at default location is not a regular file: %s", l)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
path = l
|
path = l
|
||||||
|
@ -41,8 +41,7 @@ func doControlPProf(cmd *cobra.Command, args []string) {
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx := context.WithValue(context.Background(), contextKeyLog, log)
|
conf, err := ParseConfig(rootArgs.configFile)
|
||||||
conf, err := ParseConfig(ctx, rootArgs.configFile)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("error parsing config: %s", err)
|
log.Printf("error parsing config: %s", err)
|
||||||
die()
|
die()
|
||||||
|
@ -39,15 +39,15 @@ func doDaemon(cmd *cobra.Command, args []string) {
|
|||||||
|
|
||||||
log := log.New(os.Stderr, "", log.LUTC|log.Ldate|log.Ltime)
|
log := log.New(os.Stderr, "", log.LUTC|log.Ldate|log.Ltime)
|
||||||
|
|
||||||
ctx := context.Background()
|
conf, err := ParseConfig(rootArgs.configFile)
|
||||||
ctx = context.WithValue(ctx, contextKeyLog, log)
|
|
||||||
|
|
||||||
conf, err := ParseConfig(ctx, rootArgs.configFile)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("error parsing config: %s", err)
|
log.Printf("error parsing config: %s", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ctx := context.Background()
|
||||||
|
ctx = context.WithValue(ctx, contextKeyLog, log)
|
||||||
|
|
||||||
d := NewDaemon(conf)
|
d := NewDaemon(conf)
|
||||||
d.Loop(ctx)
|
d.Loop(ctx)
|
||||||
|
|
||||||
|
@ -4,7 +4,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"context"
|
|
||||||
"github.com/ftrvxmtrx/fd"
|
"github.com/ftrvxmtrx/fd"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"io"
|
"io"
|
||||||
@ -31,8 +30,7 @@ func cmdStdinServer(cmd *cobra.Command, args []string) {
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx := context.WithValue(context.Background(), contextKeyLog, log)
|
conf, err := ParseConfig(rootArgs.configFile)
|
||||||
conf, err := ParseConfig(ctx, rootArgs.configFile)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("error parsing config: %s", err)
|
log.Printf("error parsing config: %s", err)
|
||||||
die()
|
die()
|
||||||
|
@ -66,10 +66,8 @@ func testCmdGlobalInit(cmd *cobra.Command, args []string) {
|
|||||||
|
|
||||||
testCmdGlobal.log = log.New(os.Stdout, "", 0)
|
testCmdGlobal.log = log.New(os.Stdout, "", 0)
|
||||||
|
|
||||||
ctx := context.WithValue(context.Background(), contextKeyLog, testCmdGlobal.log)
|
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
if testCmdGlobal.conf, err = ParseConfig(ctx, rootArgs.configFile); err != nil {
|
if testCmdGlobal.conf, err = ParseConfig(rootArgs.configFile); err != nil {
|
||||||
testCmdGlobal.log.Printf("error parsing config file: %s", err)
|
testCmdGlobal.log.Printf("error parsing config file: %s", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user