From 2c603ea52d1b337b77c1e655d888d8ae0b53cab9 Mon Sep 17 00:00:00 2001 From: Justin Murray Date: Wed, 20 May 2026 16:27:20 -0400 Subject: [PATCH 1/4] display user and space ids --- internal/cmd/status.go | 6 +++++- internal/common/status.go | 24 ++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/internal/cmd/status.go b/internal/cmd/status.go index ccc2090..4845be2 100644 --- a/internal/cmd/status.go +++ b/internal/cmd/status.go @@ -96,7 +96,11 @@ func outputStatus(cmd *cobra.Command, status common.Status) { } } - cmd.Println("Space Usage") + if status.UserEmail != "" { + cmd.Printf("User: %s\n", status.UserEmail) + } + cmd.Printf("Space: %s\n", status.SpaceID) + cmd.Println("\nUsage\n-----") cmd.Printf("Compute: %g/%g hours (%s)\n", computeHours, computeLimitHours, formatPercent(computePercent)) cmd.Printf("Storage: %s/1TiB (%s)\n", storageStr, formatPercent(storagePercent)) if len(parts) > 0 { diff --git a/internal/common/status.go b/internal/common/status.go index 74526b7..5885c79 100644 --- a/internal/common/status.go +++ b/internal/common/status.go @@ -38,12 +38,15 @@ type Status struct { EstimatedTotalCost *float64 `json:"estimated_total_cost,omitempty"` BillingPeriodStart *time.Time `json:"billing_period_start,omitempty"` BillingPeriodEnd *time.Time `json:"billing_period_end,omitempty"` + SpaceID string `json:"space_id"` + UserEmail string `json:"user_email,omitempty"` } // FetchStatus fetches space usage and database counts from the API. func FetchStatus(ctx context.Context, client api.ClientWithResponsesInterface, projectID string) (Status, error) { var spaceStatus *api.SpaceStatus var databases []api.DatabaseWithUsage + var email string g, ctx := errgroup.WithContext(ctx) @@ -77,6 +80,25 @@ func FetchStatus(ctx context.Context, client api.ClientWithResponsesInterface, p return nil }) + g.Go(func() error { + resp, err := client.AuthInfoWithResponse(ctx) + if err != nil { + return fmt.Errorf("failed to fetch auth info: %w", err) + } + if resp.StatusCode() != http.StatusOK { + return ExitWithErrorFromStatusCode(resp.StatusCode(), resp.JSONDefault) + } + if resp.JSON200 == nil { + return errors.New("empty response from API") + } + if resp.JSON200.User != nil { + email = resp.JSON200.User.Email + } else if resp.JSON200.ApiKey != nil { + email = resp.JSON200.ApiKey.UserEmail + } + return nil + }) + if err := g.Wait(); err != nil { return Status{}, err } @@ -120,5 +142,7 @@ func FetchStatus(ctx context.Context, client api.ClientWithResponsesInterface, p EstimatedTotalCost: spaceStatus.EstimatedTotalCost, BillingPeriodStart: spaceStatus.BillingPeriodStart, BillingPeriodEnd: spaceStatus.BillingPeriodEnd, + SpaceID: projectID, + UserEmail: email, }, nil } From 0f4030f57c89513650a6b1c38b075ee6e933a129 Mon Sep 17 00:00:00 2001 From: Justin Murray Date: Wed, 20 May 2026 16:49:00 -0400 Subject: [PATCH 2/4] remove email --- internal/cmd/status.go | 3 --- internal/common/status.go | 22 ---------------------- 2 files changed, 25 deletions(-) diff --git a/internal/cmd/status.go b/internal/cmd/status.go index 4845be2..a7db0d7 100644 --- a/internal/cmd/status.go +++ b/internal/cmd/status.go @@ -96,9 +96,6 @@ func outputStatus(cmd *cobra.Command, status common.Status) { } } - if status.UserEmail != "" { - cmd.Printf("User: %s\n", status.UserEmail) - } cmd.Printf("Space: %s\n", status.SpaceID) cmd.Println("\nUsage\n-----") cmd.Printf("Compute: %g/%g hours (%s)\n", computeHours, computeLimitHours, formatPercent(computePercent)) diff --git a/internal/common/status.go b/internal/common/status.go index 5885c79..af74727 100644 --- a/internal/common/status.go +++ b/internal/common/status.go @@ -39,14 +39,12 @@ type Status struct { BillingPeriodStart *time.Time `json:"billing_period_start,omitempty"` BillingPeriodEnd *time.Time `json:"billing_period_end,omitempty"` SpaceID string `json:"space_id"` - UserEmail string `json:"user_email,omitempty"` } // FetchStatus fetches space usage and database counts from the API. func FetchStatus(ctx context.Context, client api.ClientWithResponsesInterface, projectID string) (Status, error) { var spaceStatus *api.SpaceStatus var databases []api.DatabaseWithUsage - var email string g, ctx := errgroup.WithContext(ctx) @@ -80,25 +78,6 @@ func FetchStatus(ctx context.Context, client api.ClientWithResponsesInterface, p return nil }) - g.Go(func() error { - resp, err := client.AuthInfoWithResponse(ctx) - if err != nil { - return fmt.Errorf("failed to fetch auth info: %w", err) - } - if resp.StatusCode() != http.StatusOK { - return ExitWithErrorFromStatusCode(resp.StatusCode(), resp.JSONDefault) - } - if resp.JSON200 == nil { - return errors.New("empty response from API") - } - if resp.JSON200.User != nil { - email = resp.JSON200.User.Email - } else if resp.JSON200.ApiKey != nil { - email = resp.JSON200.ApiKey.UserEmail - } - return nil - }) - if err := g.Wait(); err != nil { return Status{}, err } @@ -143,6 +122,5 @@ func FetchStatus(ctx context.Context, client api.ClientWithResponsesInterface, p BillingPeriodStart: spaceStatus.BillingPeriodStart, BillingPeriodEnd: spaceStatus.BillingPeriodEnd, SpaceID: projectID, - UserEmail: email, }, nil } From 5408eab63d14307b33a5074d03afffc7888aaa10 Mon Sep 17 00:00:00 2001 From: Justin Murray Date: Wed, 20 May 2026 17:36:04 -0400 Subject: [PATCH 3/4] formatting --- internal/cmd/status.go | 1 - 1 file changed, 1 deletion(-) diff --git a/internal/cmd/status.go b/internal/cmd/status.go index a7db0d7..83701ad 100644 --- a/internal/cmd/status.go +++ b/internal/cmd/status.go @@ -97,7 +97,6 @@ func outputStatus(cmd *cobra.Command, status common.Status) { } cmd.Printf("Space: %s\n", status.SpaceID) - cmd.Println("\nUsage\n-----") cmd.Printf("Compute: %g/%g hours (%s)\n", computeHours, computeLimitHours, formatPercent(computePercent)) cmd.Printf("Storage: %s/1TiB (%s)\n", storageStr, formatPercent(storagePercent)) if len(parts) > 0 { From b595c56ad31f344fe5994c0e7a795b74bbf36a3d Mon Sep 17 00:00:00 2001 From: Justin Murray Date: Wed, 20 May 2026 17:40:11 -0400 Subject: [PATCH 4/4] update tests --- internal/cmd/status_test.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/internal/cmd/status_test.go b/internal/cmd/status_test.go index 8bd02eb..76ead37 100644 --- a/internal/cmd/status_test.go +++ b/internal/cmd/status_test.go @@ -120,7 +120,7 @@ func TestStatusCmd(t *testing.T) { name: "text output", args: []string{"status"}, setup: successSetup, - wantStdout: `Space Usage + wantStdout: `Space: test-project Compute: 2/10 hours (20%) Storage: 512MiB/1TiB (0%) Databases: 2 (1 running, 1 paused) @@ -138,7 +138,8 @@ Databases: 2 (1 running, 1 paused) "databases": { "running": 1, "paused": 1 - } + }, + "space_id": "test-project" } `, }, @@ -151,6 +152,7 @@ compute_minutes: 120 databases: paused: 1 running: 1 +space_id: test-project storage_limit_mib: 1.048576e+06 storage_mib: 512 `, @@ -159,7 +161,7 @@ storage_mib: 512 name: "usage alias", args: []string{"usage"}, setup: successSetup, - wantStdout: `Space Usage + wantStdout: `Space: test-project Compute: 2/10 hours (20%) Storage: 512MiB/1TiB (0%) Databases: 2 (1 running, 1 paused) @@ -188,7 +190,7 @@ Databases: 2 (1 running, 1 paused) JSON200: &databases, }, nil) }, - wantStdout: `Space Usage + wantStdout: `Space: test-project Compute: 2/10 hours (20%) Storage: 512MiB/1TiB (0%) Databases: 1 (1 running) @@ -218,7 +220,7 @@ Cost: $12.34 so far this cycle ($27.50 estimated total) JSON200: &databases, }, nil) }, - wantStdout: `Space Usage + wantStdout: `Space: test-project Compute: 2/10 hours (20%) Storage: 512MiB/1TiB (0%) Databases: 1 (1 running)