Skip to content

Commit

Permalink
opslevel get and list service commands prints properties data (#307)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbloss authored Jul 25, 2024
1 parent 1f43b99 commit 9dd1c0e
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .changes/unreleased/Feature-20240723-103058.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kind: Feature
body: get service command populates Dependents, Dependencies, and Properties data in JSON format
time: 2024-07-23T10:30:58.921742-05:00
3 changes: 3 additions & 0 deletions .changes/unreleased/Feature-20240725-105130.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kind: Feature
body: list service command optionally returns Dependents, Dependencies, and Properties data in JSON format
time: 2024-07-25T10:51:30.25075-05:00
44 changes: 38 additions & 6 deletions src/cmd/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,16 @@ var getServiceCmd = &cobra.Command{
service, err = getClientGQL().GetServiceWithAlias(key)
cobra.CheckErr(err)
}
_, err = service.GetDependents(client, nil)
cobra.CheckErr(err)
_, err = service.GetDependencies(client, nil)
cobra.CheckErr(err)
// Extra fields only displayed in JSON format
if isJsonOutput() {
_, err = service.GetDependents(client, nil)
cobra.CheckErr(err)
_, err = service.GetDependencies(client, nil)
cobra.CheckErr(err)
_, err = service.GetProperties(client, nil)
cobra.CheckErr(err)
}

common.WasFound(service.Id == "", key)
common.PrettyPrint(service)
},
Expand All @@ -87,9 +93,31 @@ var listServiceCmd = &cobra.Command{
Short: "Lists services",
Long: `Lists services`,
Run: func(cmd *cobra.Command, args []string) {
resp, err := getClientGQL().ListServices(nil)
list := resp.Nodes
var list []opslevel.Service
client := getClientGQL()
resp, err := client.ListServices(nil)
cobra.CheckErr(err)
for _, service := range resp.Nodes {
if !isJsonOutput() {
list = append(list, service)
continue
}

// Extra fields only displayed in JSON format
if ok, _ := cmd.Flags().GetBool("dependencies"); ok {
_, err = service.GetDependencies(client, nil)
cobra.CheckErr(err)
}
if ok, _ := cmd.Flags().GetBool("dependents"); ok {
_, err = service.GetDependents(client, nil)
cobra.CheckErr(err)
}
if ok, _ := cmd.Flags().GetBool("properties"); ok {
_, err = service.GetProperties(client, nil)
cobra.CheckErr(err)
}
list = append(list, service)
}
if isJsonOutput() {
common.JsonPrint(json.MarshalIndent(list, "", " "))
} else if isCsvOutput() {
Expand Down Expand Up @@ -223,6 +251,10 @@ func init() {
updateCmd.AddCommand(updateServiceCmd)
deleteCmd.AddCommand(deleteServiceCmd)

listServiceCmd.PersistentFlags().Bool("dependencies", false, "Include dependencies of each service")
listServiceCmd.PersistentFlags().Bool("dependents", false, "Include dependents of each service")
listServiceCmd.PersistentFlags().Bool("properties", false, "Include properties of each service")

importCmd.AddCommand(importServicesCmd)
}

Expand Down

0 comments on commit 9dd1c0e

Please sign in to comment.