Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix!: correctly scope flag #877

Merged
merged 1 commit into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions internal/cmd/imagerunner/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (

var (
imagerunnerClient http.ImageRunner
liveLogs bool
)

func Command(preRun func(cmd *cobra.Command, args []string)) *cobra.Command {
Expand Down Expand Up @@ -52,10 +51,9 @@ func Command(preRun func(cmd *cobra.Command, args []string)) *cobra.Command {

flags := cmd.PersistentFlags()
flags.StringVarP(&regio, "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
Expand Down
13 changes: 9 additions & 4 deletions internal/cmd/imagerunner/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 <runID>",
Short: "Fetch the logs for an imagerunner run",
Expand Down Expand Up @@ -44,26 +46,29 @@ 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
}

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
}
} 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
Expand Down
Loading