diff --git a/cmd/dagu.go b/cmd/dagu.go index 9a5bf29f2..ebfddbbc6 100644 --- a/cmd/dagu.go +++ b/cmd/dagu.go @@ -11,6 +11,7 @@ import ( "github.com/urfave/cli/v2" "github.com/yohamta/dagu/internal/admin" + "github.com/yohamta/dagu/internal/config" "github.com/yohamta/dagu/internal/constants" "github.com/yohamta/dagu/internal/utils" ) @@ -30,6 +31,12 @@ func main() { } } +func loadDAG(dagPath, params string) (cfg *config.Config, err error) { + cl := &config.Loader{BaseConfig: globalConfig.BaseConfig} + cfg, err = cl.Load(dagPath, params) + return +} + func listenSignals(abortFunc func(sig os.Signal)) { sigs = make(chan os.Signal, 1) signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM) diff --git a/cmd/dry.go b/cmd/dry.go index d2f94d8a6..41762ab87 100644 --- a/cmd/dry.go +++ b/cmd/dry.go @@ -21,9 +21,7 @@ func newDryCommand() *cli.Command { }, }, Action: func(c *cli.Context) error { - config_file_path := c.Args().Get(0) - cl := &config.Loader{BaseConfig: globalConfig.BaseConfig} - cfg, err := cl.Load(config_file_path, c.String("params")) + cfg, err := loadDAG(c.Args().Get(0), c.String("params")) if err != nil { return err } diff --git a/cmd/retry.go b/cmd/retry.go index 9ea3a53e3..792f73337 100644 --- a/cmd/retry.go +++ b/cmd/retry.go @@ -5,7 +5,6 @@ import ( "path/filepath" "github.com/yohamta/dagu" - "github.com/yohamta/dagu/internal/config" "github.com/yohamta/dagu/internal/database" "github.com/urfave/cli/v2" @@ -32,7 +31,6 @@ func newRetryCommand() *cli.Command { } func retry(f, requestId string) error { - cl := &config.Loader{BaseConfig: globalConfig.BaseConfig} db := database.Database{ Config: database.DefaultConfig(), } @@ -40,8 +38,7 @@ func retry(f, requestId string) error { if err != nil { return err } - - cfg, err := cl.Load(f, status.Status.Params) + cfg, err := loadDAG(f, status.Status.Params) if err != nil { return err } diff --git a/cmd/start.go b/cmd/start.go index 1de0162cc..d5a772179 100644 --- a/cmd/start.go +++ b/cmd/start.go @@ -22,8 +22,7 @@ func newStartCommand() *cli.Command { }, Action: func(c *cli.Context) error { config_file_path := c.Args().Get(0) - cl := &config.Loader{BaseConfig: globalConfig.BaseConfig} - cfg, err := cl.Load(config_file_path, c.String("params")) + cfg, err := loadDAG(config_file_path, c.String("params")) if err != nil { return err } diff --git a/cmd/status.go b/cmd/status.go index 80534333a..33ac86549 100644 --- a/cmd/status.go +++ b/cmd/status.go @@ -15,9 +15,7 @@ func newStatusCommand() *cli.Command { Name: "status", Usage: "dagu status ", Action: func(c *cli.Context) error { - config_file_path := c.Args().Get(0) - cl := &config.Loader{BaseConfig: globalConfig.BaseConfig} - cfg, err := cl.Load(config_file_path, "") + cfg, err := loadDAG(c.Args().Get(0), "") if err != nil { return err } diff --git a/cmd/stop.go b/cmd/stop.go index c475f7a19..797db8e8d 100644 --- a/cmd/stop.go +++ b/cmd/stop.go @@ -13,9 +13,7 @@ func newStopCommand() *cli.Command { Name: "stop", Usage: "dagu stop ", Action: func(c *cli.Context) error { - config_file_path := c.Args().Get(0) - cl := &config.Loader{BaseConfig: globalConfig.BaseConfig} - cfg, err := cl.Load(config_file_path, "") + cfg, err := loadDAG(c.Args().Get(0), "") if err != nil { return err }