From 22b981eddf218565299a82edb64f5dd6a5bc6cb7 Mon Sep 17 00:00:00 2001 From: Alex Plischke Date: Thu, 25 Jan 2024 16:57:56 -0800 Subject: [PATCH] fix!: correctly scope flag --- internal/cmd/imagerunner/cmd.go | 4 +--- internal/cmd/imagerunner/logs.go | 13 +++++++++---- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/internal/cmd/imagerunner/cmd.go b/internal/cmd/imagerunner/cmd.go index 2e4c69ee2..c553a58ea 100644 --- a/internal/cmd/imagerunner/cmd.go +++ b/internal/cmd/imagerunner/cmd.go @@ -14,7 +14,6 @@ import ( var ( imagerunnerClient http.ImageRunner - liveLogs bool ) func Command(preRun func(cmd *cobra.Command, args []string)) *cobra.Command { @@ -52,10 +51,9 @@ func Command(preRun func(cmd *cobra.Command, args []string)) *cobra.Command { flags := cmd.PersistentFlags() flags.StringVarP(®io, "region", "r", "us-west-1", "The Sauce Labs region. Options: us-west-1, eu-central-1.") - flags.BoolVarP(&liveLogs, "live-logs", "", false, "Retrieve logs from temporary livelogs storage.") cmd.AddCommand( - LogsCommand(&liveLogs), + LogsCommand(), ArtifactsCommand(), ) return cmd diff --git a/internal/cmd/imagerunner/logs.go b/internal/cmd/imagerunner/logs.go index ca8193d37..763303bc7 100644 --- a/internal/cmd/imagerunner/logs.go +++ b/internal/cmd/imagerunner/logs.go @@ -15,7 +15,9 @@ import ( "golang.org/x/text/language" ) -func LogsCommand(liveLogs *bool) *cobra.Command { +func LogsCommand() *cobra.Command { + var liveLogs bool + cmd := &cobra.Command{ Use: "logs ", Short: "Fetch the logs for an imagerunner run", @@ -44,10 +46,13 @@ func LogsCommand(liveLogs *bool) *cobra.Command { return nil }, RunE: func(cmd *cobra.Command, args []string) error { - return exec(args[0], *liveLogs) + return exec(args[0], liveLogs) }, } + flags := cmd.PersistentFlags() + flags.BoolVarP(&liveLogs, "live", "", false, "Tail the live log output from a running Sauce Orchestrate container.") + return cmd } @@ -55,7 +60,7 @@ func exec(runID string, liveLogs bool) error { if liveLogs { err := imagerunnerClient.FetchLiveLogs(context.Background(), runID) if err != nil { - if err == imgrunner.ErrResourceNotFound { + if errors.Is(err, imgrunner.ErrResourceNotFound) { return fmt.Errorf("could not find log URL for run with ID (%s): %w", runID, err) } return err @@ -63,7 +68,7 @@ func exec(runID string, liveLogs bool) error { } else { log, err := imagerunnerClient.GetLogs(context.Background(), runID) if err != nil { - if err == imgrunner.ErrResourceNotFound { + if errors.Is(err, imgrunner.ErrResourceNotFound) { return fmt.Errorf("could not find log URL for run with ID (%s): %w", runID, err) } return err