mukan-ignite/ignite/pkg/cliui/view/accountview/account.go
Mukan Erkin Törük 26b204bd04
Some checks are pending
Docs Deploy / build_and_deploy (push) Waiting to run
Generate Docs / cli (push) Waiting to run
Generate Config Doc / cli (push) Waiting to run
Go formatting / go-formatting (push) Waiting to run
Check links / markdown-link-check (push) Waiting to run
Integration / pre-test (push) Waiting to run
Integration / test on (push) Blocked by required conditions
Integration / status (push) Blocked by required conditions
Lint / Lint Go code (push) Waiting to run
Test / test (ubuntu-latest) (push) Waiting to run
feat: fork Ignite CLI v29 as Mukan Ignite — remove cosmos-sdk restrictions
2026-05-11 03:31:37 +03:00

76 lines
1.4 KiB
Go

package accountview
import (
"fmt"
"strings"
"github.com/ignite/cli/v29/ignite/pkg/cliui/colors"
"github.com/ignite/cli/v29/ignite/pkg/cliui/icons"
)
var (
fmtExistingAccount = "%s %s's account address: %s\n"
fmtNewAccount = "%s Added account %s with address %s and mnemonic:\n%s\n"
)
type Option func(*Account)
type Account struct {
Name string
Address string
Mnemonic string
}
func WithMnemonic(mnemonic string) Option {
return func(a *Account) {
a.Mnemonic = mnemonic
}
}
func NewAccount(name, address string, options ...Option) Account {
a := Account{
Name: name,
Address: address,
}
for _, apply := range options {
apply(&a)
}
return a
}
func (a Account) String() string {
name := colors.Name(a.Name)
// The account is new when the mnemonic is available
if a.Mnemonic != "" {
return fmt.Sprintf(fmtNewAccount, icons.OK, name, a.Address, colors.Mnemonic(a.Mnemonic))
}
return fmt.Sprintf(fmtExistingAccount, icons.User, name, a.Address)
}
type Accounts []Account
func (a Accounts) String() string {
b := strings.Builder{}
for i, acc := range a {
// Make sure accounts are separated by an
// empty line when the mnemonic is available.
if i > 0 && acc.Mnemonic != "" {
b.WriteRune('\n')
}
b.WriteString(acc.String())
}
b.WriteRune('\n')
return b.String()
}
func (a Accounts) Append(acc Account) Accounts {
return append(a, acc)
}