66
77 "github.com/UpCloudLtd/upcloud-cli/v3/internal/commands"
88 "github.com/UpCloudLtd/upcloud-cli/v3/internal/output"
9+ "github.com/UpCloudLtd/upcloud-go-api/v8/upcloud/request"
910 "github.com/jedib0t/go-pretty/v6/text"
1011)
1112
@@ -28,14 +29,22 @@ func (s *showCommand) ExecuteWithoutArguments(exec commands.Executor) (output.Ou
2829 return nil , err
2930 }
3031
32+ detailsAccount , err := svc .GetAccountDetails (exec .Context (), & request.GetAccountDetailsRequest {Username : account .UserName })
33+ if err != nil {
34+ return nil , err
35+ }
36+
37+ creditsFormatter := getFormatCredits (detailsAccount .Currency )
38+
3139 details := output.Details {
3240 Sections : []output.DetailSection {
3341 {
3442 Rows : []output.DetailRow {
3543 {Title : "Username:" , Key : "username" , Value : account .UserName },
36- {Title : "Credits:" , Key : "credits" , Value : account .Credits , Format : formatCredits },
44+ {Title : "Credits:" , Key : "credits" , Value : account .Credits , Format : creditsFormatter },
3745 },
3846 },
47+
3948 {
4049 Title : "Resource Limits:" , Key : "resource_limits" , Rows : []output.DetailRow {
4150 {
@@ -119,16 +128,18 @@ func (s *showCommand) ExecuteWithoutArguments(exec commands.Executor) (output.Ou
119128 }, nil
120129}
121130
122- func formatCredits (val any ) (text.Colors , string , error ) {
123- credits , ok := val .(float64 )
124- if ! ok {
125- return nil , "" , fmt .Errorf ("cannot parse %T, expected float64" , val )
126- }
131+ func getFormatCredits (currency string ) func (val any ) (text.Colors , string , error ) {
132+ return func (val any ) (text.Colors , string , error ) {
133+ credits , ok := val .(float64 )
134+ if ! ok {
135+ return nil , "" , fmt .Errorf ("cannot parse %T, expected float64" , val )
136+ }
127137
128- if math .Abs (credits ) < 0.001 {
129- return nil , "Denied" , nil
130- }
138+ if math .Abs (credits ) < 0.001 {
139+ return nil , "Denied" , nil
140+ }
131141
132- // Format does not follow european standards, but this is in sync with UI
133- return nil , fmt .Sprintf ("€%.2f" , credits / 100 ), nil
142+ // Credits are returned in cents
143+ return nil , fmt .Sprintf ("%.2f %s" , credits / 100 , currency ), nil
144+ }
134145}
0 commit comments