Skip to content

Commit

Permalink
status command read and display app metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
jfeo committed Dec 11, 2024
1 parent 8642a5f commit 06284a5
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 11 deletions.
14 changes: 9 additions & 5 deletions cmd/status/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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)
}
12 changes: 11 additions & 1 deletion cmd/status/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 9 additions & 3 deletions internal/app/app_read.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand All @@ -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)
Expand Down
8 changes: 6 additions & 2 deletions internal/app/app_read_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
Expand All @@ -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)
Expand Down

0 comments on commit 06284a5

Please sign in to comment.