@@ -69,23 +69,21 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
6969 if err != nil {
7070 return fmt .Errorf ("get scrape configurations: %w" , err )
7171 }
72- configs := * resp .Data
73- if len (configs ) == 0 {
74- instanceLabel , err := observabilityUtils .GetInstanceName (ctx , apiClient , model .InstanceId , model .ProjectId )
75- if err != nil {
76- params .Printer .Debug (print .ErrorLevel , "get instance name: %v" , err )
77- instanceLabel = model .InstanceId
78- }
79- params .Printer .Info ("No scrape configurations found for instance %q\n " , instanceLabel )
80- return nil
72+
73+ configs := resp .GetData ()
74+
75+ instanceLabel , err := observabilityUtils .GetInstanceName (ctx , apiClient , model .InstanceId , model .ProjectId )
76+ if err != nil {
77+ params .Printer .Debug (print .ErrorLevel , "get instance name: %v" , err )
78+ instanceLabel = model .InstanceId
8179 }
8280
8381 // Truncate output
8482 if model .Limit != nil && len (configs ) > int (* model .Limit ) {
8583 configs = configs [:* model .Limit ]
8684 }
8785
88- return outputResult (params .Printer , model .OutputFormat , configs )
86+ return outputResult (params .Printer , model .OutputFormat , instanceLabel , configs )
8987 },
9088 }
9189
@@ -127,8 +125,12 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *observabili
127125 return req
128126}
129127
130- func outputResult (p * print.Printer , outputFormat string , configs []observability.Job ) error {
128+ func outputResult (p * print.Printer , outputFormat , instanceLabel string , configs []observability.Job ) error {
131129 return p .OutputResult (outputFormat , configs , func () error {
130+ if len (configs ) == 0 {
131+ p .Outputf ("No scrape configurations found for instance %q\n " , instanceLabel )
132+ return nil
133+ }
132134 table := tables .NewTable ()
133135 table .SetHeader ("NAME" , "TARGETS" , "SCRAPE INTERVAL" )
134136 for i := range configs {
0 commit comments