From dacc3a49a6bb306e2f0035966073fbf57ab94c6d Mon Sep 17 00:00:00 2001 From: Jens Feodor Nielsen Date: Wed, 11 Dec 2024 14:22:42 +0100 Subject: [PATCH] status command read and display app metadata --- cmd/status/cmd.go | 14 +++++++++----- cmd/status/status.go | 12 +++++++++++- internal/app/app_read.go | 12 +++++++++--- internal/app/app_read_test.go | 8 ++++++-- 4 files changed, 35 insertions(+), 11 deletions(-) diff --git a/cmd/status/cmd.go b/cmd/status/cmd.go index 03a86126..380f8bef 100644 --- a/cmd/status/cmd.go +++ b/cmd/status/cmd.go @@ -24,9 +24,8 @@ const longFormat = `Get an overview of the status of all workloads related to an var long = fmt.Sprintf(longFormat, usage.AppIdentifier(cmdActionText), usage.AppDirectoryArgument) var cmdArgs struct { - orgSlug string - appSlug string - appDir string + appIdent args.AppIdentifierArg + appDir string } var Cmd = &cobra.Command{ @@ -42,10 +41,15 @@ func run(cmd *cobra.Command, args []string) error { input := statusInput{ appDir: cmdArgs.appDir, - appSlug: cmdArgs.appSlug, - orgSlug: cmdArgs.orgSlug, + appSlug: cmdArgs.appIdent.AppSlug, + orgSlug: cmdArgs.appIdent.OrganizationSlug, } err := status(cmd.Context(), service, input) return errorhandling.ErrorAlreadyPrinted(err) } + +func init() { + flags := Cmd.Flags() + cmdArgs.appIdent.AddAppIdentifierFlags(flags, cmdActionText) +} diff --git a/cmd/status/status.go b/cmd/status/status.go index b6ce997d..4d612e7d 100644 --- a/cmd/status/status.go +++ b/cmd/status/status.go @@ -34,12 +34,22 @@ func status(ctx context.Context, apps appReaderWorkloadLister, input statusInput return err } - workloads, err := apps.ListAppWorkloads(ctx, app.ListAppWorkloadsInput(readOutput)) + println("Name: " + readOutput.AppDisplayName) + if readOutput.AppDescription != "" { + println("Description: " + readOutput.AppDescription) + } + + workloads, err := apps.ListAppWorkloads(ctx, app.ListAppWorkloadsInput{AppID: readOutput.AppID}) if err != nil { app.PrintAppError(err, ai) return err } + println() + if len(workloads) == 0 { + println("No workloads found") + } + printWorkloads(workloads) return nil diff --git a/internal/app/app_read.go b/internal/app/app_read.go index 0c11466e..ff8d9091 100644 --- a/internal/app/app_read.go +++ b/internal/app/app_read.go @@ -12,20 +12,26 @@ type ReadAppInput struct { } type ReadAppOutput struct { - AppID string + AppID string + AppDisplayName string + AppDescription string } const queryAppText = ` query CLIAppRead($orgSlug: String!, $appSlug: String!) { app(organizationSlug: $orgSlug, appSlug: $appSlug) { id + displayName + description } } ` type appResponse struct { App struct { - ID string + ID string + DisplayName string + Description string } } @@ -35,7 +41,7 @@ func (s *Service) ReadApp(ctx context.Context, input ReadAppInput) (ReadAppOutpu variables := map[string]any{"orgSlug": input.OrganizationSlug, "appSlug": input.AppSlug} err := s.client.Exec(ctx, queryAppText, &resp, variables, graphql.OperationName("CLIAppRead")) if err == nil { - return ReadAppOutput{AppID: resp.App.ID}, nil + return ReadAppOutput{AppID: resp.App.ID, AppDisplayName: resp.App.DisplayName, AppDescription: resp.App.Description}, nil } return ReadAppOutput{}, convertErrors(err) diff --git a/internal/app/app_read_test.go b/internal/app/app_read_test.go index 7d8b6156..4c9b8eec 100644 --- a/internal/app/app_read_test.go +++ b/internal/app/app_read_test.go @@ -20,7 +20,9 @@ func TestAppRead(t *testing.T) { { "data": { "app": { - "id": "some-app-id" + "id": "some-app-id", + "displayName": "App Name", + "description": "App description" } } } @@ -35,7 +37,9 @@ func TestAppRead(t *testing.T) { output, err := s.ReadApp(context.TODO(), input) expected := ReadAppOutput{ - AppID: "some-app-id", + AppID: "some-app-id", + AppDisplayName: "App Name", + AppDescription: "App description", } assert.NoError(t, err) assert.Equal(t, expected, output)