Skip to content

Commit

Permalink
Add ID to spacectl stack list command
Browse files Browse the repository at this point in the history
Also added more specific error messages when getting run logs. Previously we were just outputting "not found" regardless of what could not be found.
  • Loading branch information
abennett authored Oct 6, 2022
1 parent 7436cf9 commit d4456b8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
4 changes: 3 additions & 1 deletion internal/cmd/stack/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ func listStacksJSON(ctx context.Context) error {
func listStacksTable(ctx context.Context) error {
var query struct {
Stacks []struct {
ID string `graphql:"id" json:"id,omitempty"`
LockedBy string `graphql:"lockedBy"`
Name string `graphql:"name"`
State string `graphql:"state"`
Expand All @@ -117,10 +118,11 @@ func listStacksTable(ctx context.Context) error {
return strings.Compare(strings.ToLower(query.Stacks[i].Name), strings.ToLower(query.Stacks[j].Name)) < 0
})

tableData := [][]string{{"Name", "Commit", "Author", "State", "Worker Pool", "Locked By"}}
tableData := [][]string{{"Name", "ID", "Commit", "Author", "State", "Worker Pool", "Locked By"}}
for _, stack := range query.Stacks {
tableData = append(tableData, []string{
stack.Name,
stack.ID,
cmd.HumanizeGitHash(stack.TrackedCommit.Hash),
stack.TrackedCommit.AuthorName,
stack.State,
Expand Down
21 changes: 16 additions & 5 deletions internal/cmd/stack/run_logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package stack

import (
"context"
"errors"
"fmt"
"time"

Expand Down Expand Up @@ -50,8 +49,12 @@ func runStates(ctx context.Context, stack, run string, sink chan<- string) (*str
return nil, err
}

if query.Stack == nil || query.Stack.Run == nil {
return nil, errors.New("not found")
if query.Stack == nil {
return nil, fmt.Errorf("stack %q not found", stack)
}

if query.Stack.Run == nil {
return nil, fmt.Errorf("run %q in stack %q not found", run, stack)
}

history := query.Stack.Run.History
Expand Down Expand Up @@ -124,8 +127,16 @@ func runStateLogs(ctx context.Context, stack, run string, state structs.RunState
return err
}

if query.Stack == nil || query.Stack.Run == nil || query.Stack.Run.Logs == nil {
return errors.New("not found")
if query.Stack == nil {
return fmt.Errorf("stack %q not found", stack)
}

if query.Stack.Run == nil {
return fmt.Errorf("run %q in stack %q not found", run, stack)
}

if query.Stack.Run.Logs == nil {
return fmt.Errorf("logs for run %q in stack %q not found", run, stack)
}

logs := query.Stack.Run.Logs
Expand Down

0 comments on commit d4456b8

Please sign in to comment.