Skip to content

Commit aba2381

Browse files
committed
Emit whoami JSON as an array in every case
whoami --format json returned a bare object for an explicit profile or environment credentials but an array for the all-profiles listing, so scripts had to branch on the invocation. Route every path through WhoamiList so the JSON output is always an array, consistent with the list and search commands.
1 parent e9985d6 commit aba2381

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

cmd/whoami.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ func whoami(cmd *cobra.Command, _ []string) error {
2626
// OP_CLI_HOST/OP_CLI_TOKEN override every stored profile, so listing file
2727
// profiles would just query the same server under different labels.
2828
if configuration.HasEnvironmentConfig() {
29-
return whoamiOne("environment")
29+
return whoamiSingle("environment")
3030
}
3131

3232
profile, explicit := resolvedProfile(cmd)
3333

3434
if explicit {
35-
return whoamiOne(profile)
35+
return whoamiSingle(profile)
3636
}
3737

3838
// No profile specified: show all profiles
@@ -67,12 +67,14 @@ func whoami(cmd *cobra.Command, _ []string) error {
6767
return nil
6868
}
6969

70-
func whoamiOne(profile string) error {
70+
// whoamiSingle renders exactly one profile as a list, so JSON output stays a
71+
// single-element array consistent with the all-profiles path.
72+
func whoamiSingle(profile string) error {
7173
entry, err := whoamiEntry(profile)
7274
if err != nil {
7375
return err
7476
}
75-
printer.Whoami(entry.Profile, entry.Host, entry.User)
77+
printer.WhoamiList([]printer.WhoamiEntry{entry})
7678
return nil
7779
}
7880

0 commit comments

Comments
 (0)