@@ -10,6 +10,7 @@ import (
1010 "github.com/stackitcloud/stackit-cli/internal/pkg/args"
1111 "github.com/stackitcloud/stackit-cli/internal/pkg/errors"
1212 "github.com/stackitcloud/stackit-cli/internal/pkg/examples"
13+ "github.com/stackitcloud/stackit-cli/internal/pkg/flags"
1314 "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
1415 "github.com/stackitcloud/stackit-cli/internal/pkg/print"
1516 "github.com/stackitcloud/stackit-cli/internal/pkg/projectname"
@@ -21,8 +22,11 @@ import (
2122
2223type inputModel struct {
2324 * globalflags.GlobalFlagModel
25+ Limit * int64
2426}
2527
28+ const limitFlag = "limit"
29+
2630func NewCmd (p * print.Printer ) * cobra.Command {
2731 cmd := & cobra.Command {
2832 Use : "list" ,
@@ -33,6 +37,10 @@ func NewCmd(p *print.Printer) *cobra.Command {
3337 examples .NewExample (
3438 `List all STACKIT Git instances` ,
3539 "$ stackit git instance list" ),
40+ examples .NewExample (
41+ "Lists up to 10 STACKIT Git instances" ,
42+ "$ stackit git instance list --limit=10" ,
43+ ),
3644 ),
3745 RunE : func (cmd * cobra.Command , _ []string ) error {
3846 ctx := context .Background ()
@@ -62,23 +70,37 @@ func NewCmd(p *print.Printer) *cobra.Command {
6270 }
6371 p .Info ("No instances found for project %q\n " , projectLabel )
6472 return nil
73+ } else if model .Limit != nil && len (instances ) > int (* model .Limit ) {
74+ instances = (instances )[:* model .Limit ]
6575 }
66-
6776 return outputResult (p , model .OutputFormat , instances )
6877 },
6978 }
70-
79+ configureFlags ( cmd )
7180 return cmd
7281}
7382
83+ func configureFlags (cmd * cobra.Command ) {
84+ cmd .Flags ().Int64 (limitFlag , 0 , "Limit the output to the first n elements" )
85+ }
86+
7487func parseInput (p * print.Printer , cmd * cobra.Command ) (* inputModel , error ) {
7588 globalFlags := globalflags .Parse (p , cmd )
7689 if globalFlags .ProjectId == "" {
7790 return nil , & errors.ProjectIdError {}
7891 }
7992
93+ limit := flags .FlagToInt64Pointer (p , cmd , limitFlag )
94+ if limit != nil && * limit < 1 {
95+ return nil , & errors.FlagValidationError {
96+ Flag : limitFlag ,
97+ Details : "must be greater than 0" ,
98+ }
99+ }
100+
80101 model := inputModel {
81102 GlobalFlagModel : globalFlags ,
103+ Limit : limit ,
82104 }
83105
84106 if p .IsVerbosityDebug () {
0 commit comments