From 708cb9d989565f37c8e647bb3849a0e4a68e6d88 Mon Sep 17 00:00:00 2001 From: Ani Channarasappa Date: Sat, 13 Feb 2021 21:45:32 -0500 Subject: [PATCH] refactor: updated function signature of validate --- cmd/root.go | 2 +- internal/cli/cli.go | 4 ++-- internal/cli/cli_test.go | 7 ++++--- 3 files changed, 7 insertions(+), 6 deletions(-) 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()) }) })