diff --git a/cmd/root.go b/cmd/root.go index 9d5625a..b32a685 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -22,7 +22,7 @@ var ( rootCmd = &cobra.Command{ Use: "ticker", Short: "Terminal stock ticker and stock gain/loss tracker", - Args: cli.Validate(dep, &ctx, &options, err), + Args: cli.Validate(&ctx, &options, &err), Run: cli.Run(ui.Start(&dep, &ctx)), } ) diff --git a/internal/cli/cli.go b/internal/cli/cli.go index 1d8962c..0269f25 100644 --- a/internal/cli/cli.go +++ b/internal/cli/cli.go @@ -39,11 +39,11 @@ func Run(uiStartFn func() error) func(*cobra.Command, []string) { } } -func Validate(dep Dependencies, ctx *Context, options *Options, prevErr error) func(*cobra.Command, []string) error { +func Validate(ctx *Context, options *Options, prevErr *error) func(*cobra.Command, []string) error { return func(cmd *cobra.Command, args []string) error { if prevErr != nil { - return prevErr + return *prevErr } if len(ctx.Config.Watchlist) == 0 && len(options.Watchlist) == 0 && len(ctx.Config.Lots) == 0 { diff --git a/internal/cli/cli_test.go b/internal/cli/cli_test.go index aa00bf3..602a894 100644 --- a/internal/cli/cli_test.go +++ b/internal/cli/cli_test.go @@ -384,7 +384,8 @@ var _ = Describe("Cli", func() { When("a deferred error is passed in", func() { It("validation fails", func() { - outputErr := Validate(c.Dependencies{}, &c.Context{}, &cli.Options{}, errors.New("some config error"))(&cobra.Command{}, []string{}) + inputErr := errors.New("some config error") + outputErr := Validate(&c.Context{}, &cli.Options{}, &inputErr)(&cobra.Command{}, []string{}) Expect(outputErr).To(MatchError("some config error")) }) }) @@ -393,7 +394,7 @@ var _ = Describe("Cli", func() { When("there is no watchlist in the config file and no watchlist cli argument", func() { It("should return an error", func() { options.Watchlist = "" - outputErr := Validate(dep, &ctx, &options, nil)(&cobra.Command{}, []string{}) + outputErr := Validate(&ctx, &options, nil)(&cobra.Command{}, []string{}) Expect(outputErr).To(MatchError("Invalid config: No watchlist provided")) }) @@ -410,7 +411,7 @@ var _ = Describe("Cli", func() { }, }, } - outputErr := Validate(dep, &ctx, &options, nil)(&cobra.Command{}, []string{}) + outputErr := Validate(&ctx, &options, nil)(&cobra.Command{}, []string{}) Expect(outputErr).NotTo(HaveOccurred()) }) })