From 9dd1c0e96a73fcbce2afa077d3e5ff831057e3bb Mon Sep 17 00:00:00 2001 From: David Bloss Date: Thu, 25 Jul 2024 10:18:39 -0700 Subject: [PATCH] opslevel get and list service commands prints properties data (#307) --- .../unreleased/Feature-20240723-103058.yaml | 3 ++ .../unreleased/Feature-20240725-105130.yaml | 3 ++ src/cmd/service.go | 44 ++++++++++++++++--- src/submodules/opslevel-go | 2 +- 4 files changed, 45 insertions(+), 7 deletions(-) create mode 100644 .changes/unreleased/Feature-20240723-103058.yaml create mode 100644 .changes/unreleased/Feature-20240725-105130.yaml diff --git a/.changes/unreleased/Feature-20240723-103058.yaml b/.changes/unreleased/Feature-20240723-103058.yaml new file mode 100644 index 00000000..fc99e360 --- /dev/null +++ b/.changes/unreleased/Feature-20240723-103058.yaml @@ -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 diff --git a/.changes/unreleased/Feature-20240725-105130.yaml b/.changes/unreleased/Feature-20240725-105130.yaml new file mode 100644 index 00000000..0d8ce898 --- /dev/null +++ b/.changes/unreleased/Feature-20240725-105130.yaml @@ -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 diff --git a/src/cmd/service.go b/src/cmd/service.go index 8541ac3e..c11c3eb4 100644 --- a/src/cmd/service.go +++ b/src/cmd/service.go @@ -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) }, @@ -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() { @@ -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) } diff --git a/src/submodules/opslevel-go b/src/submodules/opslevel-go index 0a0e2c7d..d86d73be 160000 --- a/src/submodules/opslevel-go +++ b/src/submodules/opslevel-go @@ -1 +1 @@ -Subproject commit 0a0e2c7d14cfc56033521c27aa8ca4ada4e81c25 +Subproject commit d86d73be1df10da04205beb5741c329470c2788f