Print an empty unlocker or vault list as [] in JSON (closes #148)
check / check (push) Waiting to run
check / check (push) Waiting to run
`secret unlocker list --json` printed "unlockers": null for a vault with no unlockers, and `secret vault list --json` printed "vaults": null when vaults.d held no vaults. Both lists were nil slices, which encoding/json writes as null. Each is now made as an empty slice before it is filled, so an empty list prints as []. vault.ListVaults therefore returns an empty slice instead of nil for an empty vaults.d; its other callers only range over the result or check its length. Model: opus-5-5
This commit was merged in pull request #178.
This commit is contained in:
@@ -314,7 +314,8 @@ func (cli *Instance) UnlockersList(jsonOutput bool) error {
|
||||
return err
|
||||
}
|
||||
|
||||
var unlockers []UnlockerInfo
|
||||
// Not nil, so that a vault with no unlockers prints [] in JSON, not null
|
||||
unlockers := make([]UnlockerInfo, 0, len(unlockerMetadata))
|
||||
|
||||
for _, unlockerID := range slices.Sorted(maps.Keys(unlockerMetadata)) {
|
||||
metadata := unlockerMetadata[unlockerID]
|
||||
|
||||
Reference in New Issue
Block a user