Files
RAGOT DavidandGitHub 0df34a4d94 feat: fctl output=<json> (#363)
+ Add controller interface
+ Add renderable interface

- A controller define his store. And Running cycle returning a renderable interface
- Json is handle between Run & Render is the proper flag is set
2023-07-07 09:36:12 +02:00

53 lines
1.3 KiB
Go

package views
import (
"fmt"
"io"
fctl "github.com/formancehq/fctl/pkg"
"github.com/formancehq/formance-sdk-go/pkg/models/shared"
"github.com/pterm/pterm"
)
func PrintWallet(out io.Writer, wallet shared.WalletWithBalances) error {
fctl.Section.Println("Information")
tableData := pterm.TableData{}
tableData = append(tableData, []string{pterm.LightCyan("ID"), fmt.Sprint(wallet.ID)})
tableData = append(tableData, []string{pterm.LightCyan("Name"), wallet.Name})
if err := pterm.DefaultTable.
WithWriter(out).
WithData(tableData).
Render(); err != nil {
return err
}
fctl.Section.Println("Balances")
if len(wallet.Balances.Main.Assets) == 0 {
fctl.Println("No balances found.")
return nil
}
tableData = pterm.TableData{}
tableData = append(tableData, []string{"Asset", "Amount"})
for asset, amount := range wallet.Balances.Main.Assets {
tableData = append(tableData, []string{asset, fmt.Sprint(amount)})
}
if err := pterm.DefaultTable.
WithHasHeader(true).
WithWriter(out).
WithData(tableData).
Render(); err != nil {
return err
}
return nil
}
func PrintWalletWithMetadata(out io.Writer, wallet shared.WalletWithBalances) error {
err := PrintWallet(out, wallet)
if err != nil {
return err
}
return fctl.PrintMetadata(out, wallet.Metadata)
}