Skip to content

Conversation

@cgoetz-inovex
Copy link

@cgoetz-inovex cgoetz-inovex commented Nov 19, 2025

Description

Issue: STACKITCLI-70

relates to #1234

Checklist

  • Issue was linked above
  • Code format was applied: make fmt
  • Examples were added / adjusted (see e.g. here)
  • Docs are up-to-date: make generate-docs (will be checked by CI)
  • Unit tests got implemented or updated
  • Unit tests are passing: make test (will be checked by CI)
  • No linter issues: make lint (will be checked by CI)

@cgoetz-inovex cgoetz-inovex requested a review from a team as a code owner November 19, 2025 16:39
return cmd
}

var sortByFlagOptions = []string{"id", "created", "updated", "origin-url", "status"}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please directly use directly the API values: "id" "updatedAt" "createdAt" "originUrl" "status" "originUrlRelated"

This was wrong in the Jira story.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe there's also a enum generated in the SDK which holds these values. Then this would be the way to go because it will be kept up-to-date in the future without any efforts on our side.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Searched for sortBy and originUrl etc. could not find an enum for this. The spec looks like it should generate an enum: https://github.com/stackitcloud/stackit-api-specifications/blob/83214868e6dbdc53d053cc07654542d8f34b5491/services/cdn/v1beta2/cdn.json#L1486

How could I start to investigate this further?


func outputResult(p *print.Printer, outputFormat string, distributions []cdn.Distribution) error {
if distributions == nil {
distributions = make([]cdn.Distribution, 0) // otherwise prints null in json output
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good catch indeed! Any chance we can solve this in a central place for all commands?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice idea, I'll investigate this a bit, don't know much about go reflection yet.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With reflection I'd add this in Printer.OutputResult():

	val := reflect.ValueOf(output)
	if val.IsNil() {
		// when passing a nil slice or map, JSON and YAML marshal to "null"
		// so we need to create an empty slice or map to have "[]" or "{}" output instead
		switch val.Kind() {
		case reflect.Slice:
			output = make([]any, 0)
		case reflect.Map:
			output = make(map[any]any)
		default:
			// do nothing
		}
	}

The linked document suggests type switches, which would not work here.

Another solution without reflection, that comes to mind, would be to introduce specialized OutputResult functions, like OutputResultSlice/Map.

var testProjectId = uuid.NewString()
var testClient = &cdn.APIClient{}
var testCtx = context.WithValue(context.Background(), "foo", "foo")
var testNextPageID = "next-page-id-123"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could be const I guess 😅 (yeah I know, nitpick)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to take the address of testNextPageID in some tests to pass it to the generated API -> const does not work.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nvm. just discovered utils.Ptr() for this.

var testCtx = context.WithValue(context.Background(), "foo", "foo")
var testNextPageID = "next-page-id-123"
var testTime = time.Now()
var testID = "dist-1"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also need the address of this one.

@rubenhoenle
Copy link
Member

Btw, please always add the Jira issue ID to your PR description if possible :)

}

table := tables.NewTable()
table.SetHeader("ID", "REGIONS", "STATUS")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rubenhoenle, when using the table output we only get these columns. When using the JSON format we would get all fields of cdn.Distribution. Should I introduce here custom struct that only contains ID, REGIONS and STATUS in JSON?

@github-actions
Copy link

Merging this branch changes the coverage (1 decrease, 3 increase)

Impacted Packages Coverage Δ 🤖
github.com/stackitcloud/stackit-cli/internal/cmd/beta/cdn 0.00% (ø)
github.com/stackitcloud/stackit-cli/internal/cmd/beta/cdn/distribution 0.00% (ø)
github.com/stackitcloud/stackit-cli/internal/cmd/beta/cdn/distribution/list 78.57% (+78.57%) 🌟
github.com/stackitcloud/stackit-cli/internal/cmd/config/set 90.00% (+0.24%) 👍
github.com/stackitcloud/stackit-cli/internal/cmd/config/unset 35.40% (-0.06%) 👎
github.com/stackitcloud/stackit-cli/internal/pkg/config 71.38% (+0.11%) 👍
github.com/stackitcloud/stackit-cli/internal/pkg/services/cdn/client 0.00% (ø)

Coverage by file

Changed files (no unit tests)

Changed File Coverage Δ Total Covered Missed 🤖
github.com/stackitcloud/stackit-cli/internal/cmd/beta/cdn/cdn.go 0.00% (ø) 4 (+4) 0 4 (+4)
github.com/stackitcloud/stackit-cli/internal/cmd/beta/cdn/distribution/distribution.go 0.00% (ø) 4 (+4) 0 4 (+4)
github.com/stackitcloud/stackit-cli/internal/cmd/beta/cdn/distribution/list/list.go 78.57% (+78.57%) 56 (+56) 44 (+44) 12 (+12) 🌟
github.com/stackitcloud/stackit-cli/internal/cmd/config/set/set.go 90.00% (+0.24%) 130 (+3) 117 (+3) 13 👍
github.com/stackitcloud/stackit-cli/internal/cmd/config/unset/unset.go 35.40% (-0.06%) 113 (+3) 40 (+1) 73 (+2) 👎
github.com/stackitcloud/stackit-cli/internal/pkg/config/config.go 90.32% (+0.16%) 62 (+1) 56 (+1) 6 👍
github.com/stackitcloud/stackit-cli/internal/pkg/services/cdn/client/client.go 0.00% (ø) 1 (+1) 0 1 (+1)

Please note that the "Total", "Covered", and "Missed" counts above refer to code statements instead of lines of code. The value in brackets refers to the test coverage of that file in the old version of the code.

Changed unit test files

  • github.com/stackitcloud/stackit-cli/internal/cmd/beta/cdn/distribution/list/list_test.go
  • github.com/stackitcloud/stackit-cli/internal/cmd/config/unset/unset_test.go

@github-actions
Copy link

Merging this branch changes the coverage (1 decrease, 3 increase)

Impacted Packages Coverage Δ 🤖
github.com/stackitcloud/stackit-cli/internal/cmd/beta 0.00% (ø)
github.com/stackitcloud/stackit-cli/internal/cmd/beta/cdn 0.00% (ø)
github.com/stackitcloud/stackit-cli/internal/cmd/beta/cdn/distribution 0.00% (ø)
github.com/stackitcloud/stackit-cli/internal/cmd/beta/cdn/distribution/list 78.57% (+78.57%) 🌟
github.com/stackitcloud/stackit-cli/internal/cmd/config/set 90.00% (+0.24%) 👍
github.com/stackitcloud/stackit-cli/internal/cmd/config/unset 35.40% (-0.06%) 👎
github.com/stackitcloud/stackit-cli/internal/pkg/config 71.38% (+0.11%) 👍
github.com/stackitcloud/stackit-cli/internal/pkg/services/cdn/client 0.00% (ø)

Coverage by file

Changed files (no unit tests)

Changed File Coverage Δ Total Covered Missed 🤖
github.com/stackitcloud/stackit-cli/internal/cmd/beta/beta.go 0.00% (ø) 7 (+1) 0 7 (+1)
github.com/stackitcloud/stackit-cli/internal/cmd/beta/cdn/cdn.go 0.00% (ø) 4 (+4) 0 4 (+4)
github.com/stackitcloud/stackit-cli/internal/cmd/beta/cdn/distribution/distribution.go 0.00% (ø) 4 (+4) 0 4 (+4)
github.com/stackitcloud/stackit-cli/internal/cmd/beta/cdn/distribution/list/list.go 78.57% (+78.57%) 56 (+56) 44 (+44) 12 (+12) 🌟
github.com/stackitcloud/stackit-cli/internal/cmd/config/set/set.go 90.00% (+0.24%) 130 (+3) 117 (+3) 13 👍
github.com/stackitcloud/stackit-cli/internal/cmd/config/unset/unset.go 35.40% (-0.06%) 113 (+3) 40 (+1) 73 (+2) 👎
github.com/stackitcloud/stackit-cli/internal/pkg/config/config.go 90.32% (+0.16%) 62 (+1) 56 (+1) 6 👍
github.com/stackitcloud/stackit-cli/internal/pkg/services/cdn/client/client.go 0.00% (ø) 1 (+1) 0 1 (+1)

Please note that the "Total", "Covered", and "Missed" counts above refer to code statements instead of lines of code. The value in brackets refers to the test coverage of that file in the old version of the code.

Changed unit test files

  • github.com/stackitcloud/stackit-cli/internal/cmd/beta/cdn/distribution/list/list_test.go
  • github.com/stackitcloud/stackit-cli/internal/cmd/config/unset/unset_test.go

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants