@@ -61,19 +61,20 @@ func NewCmd(params *params.CmdParams) *cobra.Command {
6161 if err != nil {
6262 return fmt .Errorf ("get STACKIT Git instances: %w" , err )
6363 }
64- instances := * resp .Instances
65- if len ( instances ) == 0 {
66- projectLabel , err := projectname .GetProjectName (ctx , params .Printer , params .CliVersion , cmd )
67- if err != nil {
68- params .Printer .Debug (print .ErrorLevel , "get project name: %v" , err )
69- projectLabel = model .ProjectId
70- }
71- params . Printer . Info ( "No instances found for project %q \n " , projectLabel )
72- return nil
73- } else if model .Limit != nil && len (instances ) > int (* model .Limit ) {
64+ instances := resp .GetInstances ()
65+
66+ projectLabel , err := projectname .GetProjectName (ctx , params .Printer , params .CliVersion , cmd )
67+ if err != nil {
68+ params .Printer .Debug (print .ErrorLevel , "get project name: %v" , err )
69+ projectLabel = model .ProjectId
70+ }
71+
72+ // Truncate output
73+ if model .Limit != nil && len (instances ) > int (* model .Limit ) {
7474 instances = (instances )[:* model .Limit ]
7575 }
76- return outputResult (params .Printer , model .OutputFormat , instances )
76+
77+ return outputResult (params .Printer , model .OutputFormat , projectLabel , instances )
7778 },
7879 }
7980 configureFlags (cmd )
@@ -111,8 +112,13 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *git.APIClie
111112 return apiClient .ListInstances (ctx , model .ProjectId )
112113}
113114
114- func outputResult (p * print.Printer , outputFormat string , instances []git.Instance ) error {
115+ func outputResult (p * print.Printer , outputFormat , projectLabel string , instances []git.Instance ) error {
115116 return p .OutputResult (outputFormat , instances , func () error {
117+ if len (instances ) == 0 {
118+ p .Outputf ("No instances found for project %q\n " , projectLabel )
119+ return nil
120+ }
121+
116122 table := tables .NewTable ()
117123 table .SetHeader ("ID" , "NAME" , "URL" , "VERSION" , "STATE" , "CREATED" )
118124 for i := range instances {
0 commit comments