Skip to content

Commit

Permalink
api.ListNamespaceOrbs returns a slice of Orbs instead of just err
Browse files Browse the repository at this point in the history
This allows the `cmd` package to handle the printing of the data
  • Loading branch information
Zachary Scott committed Aug 31, 2018
1 parent 67a7692 commit a2111dd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
12 changes: 7 additions & 5 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)

Expand All @@ -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:
Expand All @@ -812,13 +813,14 @@ 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)
}
}

if !result.RegistryNamespace.Orbs.PageInfo.HasNextPage {
break
}
}
return nil

return orbs, nil
}
5 changes: 4 additions & 1 deletion cmd/orb.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit a2111dd

Please sign in to comment.