Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/stackit_git_instance_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ stackit git instance create [flags]
$ stackit git instance create --name my-new-instance

Create a instance with name 'my-new-instance' and flavor
$ stackit git instance create --name my-new-instance --flavor git-100'
$ stackit git instance create --name my-new-instance --flavor git-100

Create a instance with name 'my-new-instance' and acl
$ stackit git instance create --name my-new-instance --acl 1.1.1.1/1'
$ stackit git instance create --name my-new-instance --acl 1.1.1.1/1
```

### Options
Expand Down
30 changes: 18 additions & 12 deletions internal/cmd/git/flavor/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,20 @@ func NewCmd(params *params.CmdParams) *cobra.Command {
if err != nil {
return fmt.Errorf("get STACKIT Git flavors: %w", err)
}
flavors := *resp.Flavors
if len(flavors) == 0 {
projectLabel, err := projectname.GetProjectName(ctx, params.Printer, params.CliVersion, cmd)
if err != nil {
params.Printer.Debug(print.ErrorLevel, "get project name: %v", err)
projectLabel = model.ProjectId
}
params.Printer.Info("No flavors found for project %q\n", projectLabel)
return nil
} else if model.Limit != nil && len(flavors) > int(*model.Limit) {
flavors := resp.GetFlavors()

projectLabel, err := projectname.GetProjectName(ctx, params.Printer, params.CliVersion, cmd)
if err != nil {
params.Printer.Debug(print.ErrorLevel, "get project name: %v", err)
projectLabel = model.ProjectId
}

// Truncate output
if model.Limit != nil && len(flavors) > int(*model.Limit) {
flavors = (flavors)[:*model.Limit]
}
return outputResult(params.Printer, model.OutputFormat, flavors)

return outputResult(params.Printer, model.OutputFormat, projectLabel, flavors)
},
}
configureFlags(cmd)
Expand Down Expand Up @@ -110,8 +111,13 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *git.APIClie
return apiClient.ListFlavors(ctx, model.ProjectId)
}

func outputResult(p *print.Printer, outputFormat string, flavors []git.Flavor) error {
func outputResult(p *print.Printer, outputFormat, projectLabel string, flavors []git.Flavor) error {
return p.OutputResult(outputFormat, flavors, func() error {
if len(flavors) == 0 {
p.Outputf("No flavors found for project %q\n", projectLabel)
return nil
}

table := tables.NewTable()
table.SetHeader("ID", "DESCRIPTION", "DISPLAY_NAME", "AVAILABLE", "SKU")
for i := range flavors {
Expand Down
3 changes: 2 additions & 1 deletion internal/cmd/git/flavor/list/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ func TestBuildRequest(t *testing.T) {
func TestOutputResult(t *testing.T) {
type args struct {
outputFormat string
projectLabel string
flavors []git.Flavor
}
tests := []struct {
Expand Down Expand Up @@ -192,7 +193,7 @@ func TestOutputResult(t *testing.T) {
p.Cmd = NewCmd(&params.CmdParams{Printer: p})
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if err := outputResult(p, tt.args.outputFormat, tt.args.flavors); (err != nil) != tt.wantErr {
if err := outputResult(p, tt.args.outputFormat, tt.args.projectLabel, tt.args.flavors); (err != nil) != tt.wantErr {
t.Errorf("outputResult() error = %v, wantErr %v", err, tt.wantErr)
}
})
Expand Down
4 changes: 2 additions & 2 deletions internal/cmd/git/instance/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ func NewCmd(params *params.CmdParams) *cobra.Command {
),
examples.NewExample(
`Create a instance with name 'my-new-instance' and flavor`,
`$ stackit git instance create --name my-new-instance --flavor git-100'`,
`$ stackit git instance create --name my-new-instance --flavor git-100`,
),
examples.NewExample(
`Create a instance with name 'my-new-instance' and acl`,
`$ stackit git instance create --name my-new-instance --acl 1.1.1.1/1'`,
`$ stackit git instance create --name my-new-instance --acl 1.1.1.1/1`,
),
),
RunE: func(cmd *cobra.Command, args []string) (err error) {
Expand Down
30 changes: 18 additions & 12 deletions internal/cmd/git/instance/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,20 @@ func NewCmd(params *params.CmdParams) *cobra.Command {
if err != nil {
return fmt.Errorf("get STACKIT Git instances: %w", err)
}
instances := *resp.Instances
if len(instances) == 0 {
projectLabel, err := projectname.GetProjectName(ctx, params.Printer, params.CliVersion, cmd)
if err != nil {
params.Printer.Debug(print.ErrorLevel, "get project name: %v", err)
projectLabel = model.ProjectId
}
params.Printer.Info("No instances found for project %q\n", projectLabel)
return nil
} else if model.Limit != nil && len(instances) > int(*model.Limit) {
instances := resp.GetInstances()

projectLabel, err := projectname.GetProjectName(ctx, params.Printer, params.CliVersion, cmd)
if err != nil {
params.Printer.Debug(print.ErrorLevel, "get project name: %v", err)
projectLabel = model.ProjectId
}

// Truncate output
if model.Limit != nil && len(instances) > int(*model.Limit) {
instances = (instances)[:*model.Limit]
}
return outputResult(params.Printer, model.OutputFormat, instances)

return outputResult(params.Printer, model.OutputFormat, projectLabel, instances)
},
}
configureFlags(cmd)
Expand Down Expand Up @@ -111,8 +112,13 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *git.APIClie
return apiClient.ListInstances(ctx, model.ProjectId)
}

func outputResult(p *print.Printer, outputFormat string, instances []git.Instance) error {
func outputResult(p *print.Printer, outputFormat, projectLabel string, instances []git.Instance) error {
return p.OutputResult(outputFormat, instances, func() error {
if len(instances) == 0 {
p.Outputf("No instances found for project %q\n", projectLabel)
return nil
}

table := tables.NewTable()
table.SetHeader("ID", "NAME", "URL", "VERSION", "STATE", "CREATED")
for i := range instances {
Expand Down
3 changes: 2 additions & 1 deletion internal/cmd/git/instance/list/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ func TestBuildRequest(t *testing.T) {
func TestOutputResult(t *testing.T) {
type args struct {
outputFormat string
projectLabel string
instances []git.Instance
}
tests := []struct {
Expand Down Expand Up @@ -192,7 +193,7 @@ func TestOutputResult(t *testing.T) {
p.Cmd = NewCmd(&params.CmdParams{Printer: p})
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if err := outputResult(p, tt.args.outputFormat, tt.args.instances); (err != nil) != tt.wantErr {
if err := outputResult(p, tt.args.outputFormat, tt.args.projectLabel, tt.args.instances); (err != nil) != tt.wantErr {
t.Errorf("outputResult() error = %v, wantErr %v", err, tt.wantErr)
}
})
Expand Down
Loading