From a2111dd50aafa12c8b6887b134392d7b7b02430f Mon Sep 17 00:00:00 2001 From: Zachary Scott Date: Fri, 31 Aug 2018 12:19:44 +0900 Subject: [PATCH] api.ListNamespaceOrbs returns a slice of Orbs instead of just err This allows the `cmd` package to handle the printing of the data --- api/api.go | 12 +++++++----- cmd/orb.go | 5 ++++- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/api/api.go b/api/api.go index b1a39cf93..1b9289f24 100644 --- a/api/api.go +++ b/api/api.go @@ -726,7 +726,7 @@ func OrbSource(ctx context.Context, logger *logger.Logger, namespace string, orb // ListNamespaceOrbs queries the API to find all orbs belonging to the given // namespace. Prints the orbs and their jobs and commands to the supplied // logger. -func ListNamespaceOrbs(ctx context.Context, logger *logger.Logger, namespace string) error { +func ListNamespaceOrbs(ctx context.Context, logger *logger.Logger, namespace string) ([]Orb, error) { // Define a structure that matches the result of the GQL // query, so that we can use mapstructure to convert from // nested maps to a strongly typed struct. @@ -775,10 +775,11 @@ query namespaceOrbs ($namespace: String, $after: String!) { } } ` + var orbs []Orb address, err := GraphQLServerAddress(EnvEndpointHost()) if err != nil { - return err + return orbs, err } graphQLclient := client.NewClient(address, logger) @@ -792,7 +793,7 @@ query namespaceOrbs ($namespace: String, $after: String!) { err := graphQLclient.Run(ctx, request, &result) if err != nil { - return errors.Wrap(err, "GraphQL query failed") + return orbs, errors.Wrap(err, "GraphQL query failed") } NamespaceOrbs: @@ -812,7 +813,7 @@ query namespaceOrbs ($namespace: String, $after: String!) { logger.Error(fmt.Sprintf("Corrupt Orb %s %s", edge.Node.Name, v.Version), err) continue NamespaceOrbs } - logger.Info(o.String()) + orbs = append(orbs, o) } } @@ -820,5 +821,6 @@ query namespaceOrbs ($namespace: String, $after: String!) { break } } - return nil + + return orbs, nil } diff --git a/cmd/orb.go b/cmd/orb.go index 16044a173..66639dcc9 100644 --- a/cmd/orb.go +++ b/cmd/orb.go @@ -244,10 +244,13 @@ query ListOrbs ($after: String!) { func listNamespaceOrbs(namespace string) error { ctx := context.Background() - err := api.ListNamespaceOrbs(ctx, Logger, namespace) + orbs, err := api.ListNamespaceOrbs(ctx, Logger, namespace) if err != nil { return errors.Wrapf(err, "Failed to list orbs in namespace %s", namespace) } + for _, o := range orbs { + Logger.Info(o.String()) + } return nil }