Skip to content

feat(fxconfig): add --format flag to namespace list with JSON/YAML output#234

Open
pradhyum6144 wants to merge 1 commit into
hyperledger:mainfrom
pradhyum6144:feat/namespace-list-format-flag
Open

feat(fxconfig): add --format flag to namespace list with JSON/YAML output#234
pradhyum6144 wants to merge 1 commit into
hyperledger:mainfrom
pradhyum6144:feat/namespace-list-format-flag

Conversation

@pradhyum6144

@pradhyum6144 pradhyum6144 commented May 3, 2026

Copy link
Copy Markdown

Type of change

  • New feature
  • Improvement (improvement to code, performance, etc)

Description

Adds a --format flag (json|yaml|table) to fxconfig namespace list.
The default table format preserves the existing output exactly for
backward compatibility.

For json and yaml, the command serialises a typed slice with the
following fields per namespace:

Field Description
name Namespace identifier
version Current version number
policy Raw policy bytes (base64 in JSON)
policyString Human-readable decoded policy

Policy decoding (policyString) is implemented in the CLI layer:

  • ThresholdRule → base64-encoded public key
  • MspRule → proto text of SignaturePolicyEnvelope
  • Unknown/invalid bytes → hex fallback

The commented-out parsePolicy stub in app/list.go is removed. It
targeted common.SignaturePolicy rather than common.SignaturePolicyEnvelope
(the actual type produced by policydsl.FromString), and used panics for
error handling. The correct implementation now lives in the CLI layer where
display concerns belong.

Additional details (Optional)

Tests added:

  • TestNewListCommandRunJSON — validates JSON structure and field presence
  • TestNewListCommandRunYAML — validates name and version fields in YAML
  • TestNewListCommandRunInvalidFormat — invalid format returns descriptive error
  • Updated TestNewListCommandRun to use cmd.SetOut (idiomatic Cobra test pattern)

All unit tests pass: go test ./fxconfig/internal/...
Lint clean: golangci-lint run --new-from-rev=origin/main ./fxconfig/...

Example usage after this change:

# pipe into jq for scripting
fxconfig namespace list --format json | jq '.[].name'

# YAML for human inspection
fxconfig namespace list --format yaml

…tput

Adds structured output support to 'fxconfig namespace list' via a new
--format flag (json|yaml|table). The table format preserves the existing
output for backward compatibility.

For json and yaml formats, the command serialises a typed slice whose
fields include a decoded policyString alongside the raw policy bytes.
Policy decoding is implemented in the CLI layer:
- ThresholdRule → base64-encoded public key
- MspRule → proto text representation of SignaturePolicyEnvelope
- Unknown/invalid → hex fallback

The commented-out parsePolicy stub in app/list.go (which had the wrong
unmarshal target type — SignaturePolicy instead of
SignaturePolicyEnvelope) is removed; the correct implementation now
lives in the CLI layer where display concerns belong.

Tests added:
- JSON output validates structure and field presence
- YAML output validates name and version fields
- Invalid format returns a descriptive error

Signed-off-by: pradhyum6144 <pradhyum314@gmail.com>
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.

1 participant