diff --git a/pkg/cli/cli.go b/pkg/cli/cli.go index 64809f7..a442bf7 100644 --- a/pkg/cli/cli.go +++ b/pkg/cli/cli.go @@ -35,7 +35,22 @@ const ( ) // runConduitCmdWithConfig run the main logic with a supplied conduit config -func runConduitCmdWithConfig(pCfg *data.Config) error { +func runConduitCmdWithConfig(args *data.Args) error { + defer pipeline.HandlePanic(logger) + + if args.ConduitDataDir == "" { + args.ConduitDataDir = os.Getenv(conduitEnvVar) + } + + if args.ConduitDataDir == "" { + return fmt.Errorf("the data directory is required and must be provided with a command line option or the '%s' environment variable", conduitEnvVar) + } + + pCfg, err := data.MakePipelineConfig(args) + if err != nil { + return err + } + // Initialize logger level, err := log.ParseLevel(pCfg.LogLevel) if err != nil { @@ -52,7 +67,7 @@ func runConduitCmdWithConfig(pCfg *data.Config) error { } logger.Infof("Starting Conduit %s", version.LongVersion()) - logger.Infof("Using data directory: %s", pCfg.ConduitArgs.ConduitDataDir) + logger.Infof("Using data directory: %s", args.ConduitDataDir) logger.Info("Conduit configuration is valid") if !pCfg.HideBanner { @@ -105,26 +120,6 @@ func runConduitCmdWithConfig(pCfg *data.Config) error { return pipeline.Error() } -// runConduitCmdWithArgs run the main logic with a supplied conduit args -func runConduitCmdWithArgs(args *data.Args) error { - defer pipeline.HandlePanic(logger) - - if args.ConduitDataDir == "" { - args.ConduitDataDir = os.Getenv(conduitEnvVar) - } - - if args.ConduitDataDir == "" { - return fmt.Errorf("the data directory is required and must be provided with a command line option or the '%s' environment variable", conduitEnvVar) - } - - pCfg, err := data.MakePipelineConfig(args) - if err != nil { - return err - } - - return runConduitCmdWithConfig(pCfg) -} - // MakeConduitCmdWithUtilities creates the main cobra command with all utilities func MakeConduitCmdWithUtilities() *cobra.Command { cmd := MakeConduitCmd() @@ -152,7 +147,7 @@ See other subcommands for further built in utilities and information. Detailed documentation is online: https://github.com/algorand/conduit`, Args: cobra.NoArgs, Run: func(cmd *cobra.Command, args []string) { - err := runConduitCmdWithArgs(cfg) + err := runConduitCmdWithConfig(cfg) if err != nil { fmt.Fprintf(os.Stderr, "\nExiting with error:\n%s.\n", err) os.Exit(1) diff --git a/pkg/cli/cli_test.go b/pkg/cli/cli_test.go index c700787..a46f12e 100644 --- a/pkg/cli/cli_test.go +++ b/pkg/cli/cli_test.go @@ -47,7 +47,7 @@ func TestBanner(t *testing.T) { } args := setupDataDir(t, cfg) - err = runConduitCmdWithArgs(args) + err = runConduitCmdWithConfig(args) data, err := os.ReadFile(stdoutFilePath) require.NoError(t, err) @@ -69,7 +69,7 @@ func TestBanner(t *testing.T) { func TestEmptyDataDir(t *testing.T) { args := data.Args{} - err := runConduitCmdWithArgs(&args) + err := runConduitCmdWithConfig(&args) require.ErrorContains(t, err, conduitEnvVar) } @@ -78,7 +78,7 @@ func TestInvalidLogLevel(t *testing.T) { LogLevel: "invalid", } args := setupDataDir(t, cfg) - err := runConduitCmdWithArgs(args) + err := runConduitCmdWithConfig(args) require.ErrorContains(t, err, "not a valid log level") } @@ -104,7 +104,7 @@ func TestLogFile(t *testing.T) { } args := setupDataDir(t, cfg) - err = runConduitCmdWithArgs(args) + err = runConduitCmdWithConfig(args) require.ErrorContains(t, err, "pipeline creation error") return os.ReadFile(stdoutFilePath) }