Skip to content

All CLI JSON output is wrapped in a slice of one item #6654

@alec-w

Description

@alec-w

In pkg/common/cliprinter/cliprinter.go the PrintStruct method causes its arguments to wrapped in a second slice before printing them

func (p *printer) PrintStruct(msg ...any) error {
	return p.printStruct(msg)
}

because the internal method is variadic too

func (p *printer) printStruct(msg ...any) error

This is in contrast to PrintProto which unwraps the args before passing them on (so doesn't wrap them in an extra slice).

func (p *printer) PrintProto(msg ...proto.Message) error {
	return p.printProto(msg...)
}

Its unclear if this is intentional or not.

It caused a problem for me as I was modifying cmd/spire-server/cli/jwt/mint.go to support giving output conforming to https://kubernetes.io/docs/reference/config-api/client-authentication.v1/#client-authentication-k8s-io-v1-ExecCredentialStatus - but could not with the cliprinter as is because any json output was wrapped as an array of one item.

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority/backlogIssue is approved and in the backlog

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions