Skip to content

Commit

Permalink
Revert some unnecessary refactoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
winder committed Aug 17, 2023
1 parent a1be085 commit c7a5dc3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 27 deletions.
41 changes: 18 additions & 23 deletions pkg/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Check warning on line 52 in pkg/cli/cli.go

View check run for this annotation

Codecov / codecov/patch

pkg/cli/cli.go#L51-L52

Added lines #L51 - L52 were not covered by tests

// Initialize logger
level, err := log.ParseLevel(pCfg.LogLevel)
if err != nil {
Expand All @@ -52,7 +67,7 @@ func runConduitCmdWithConfig(pCfg *data.Config) error {
}

Check warning on line 67 in pkg/cli/cli.go

View check run for this annotation

Codecov / codecov/patch

pkg/cli/cli.go#L66-L67

Added lines #L66 - L67 were not covered by tests

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 {
Expand Down Expand Up @@ -105,26 +120,6 @@ func runConduitCmdWithConfig(pCfg *data.Config) error {
return pipeline.Error()

Check warning on line 120 in pkg/cli/cli.go

View check run for this annotation

Codecov / codecov/patch

pkg/cli/cli.go#L119-L120

Added lines #L119 - L120 were not covered by tests
}

// 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()
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions pkg/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)
}

Expand All @@ -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")
}

Expand All @@ -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)
}
Expand Down

0 comments on commit c7a5dc3

Please sign in to comment.