output

package
v2.3.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 20, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Format string

Format is the target of output-format flag

View Source
var NonInteractive bool

NonInteractive when set, interactive prompts return error instead of waiting for input. Automatically set when stdin is not a terminal, or via --non-interactive flag / IOCTL_NON_INTERACTIVE=1 env.

View Source
var Quiet bool

Quiet when set, suppresses informational lines (e.g. "Blockchain Node: ...") and only outputs data.

Functions

func Confirm added in v2.3.6

func Confirm(info string) (bool, error)

Confirm displays a confirmation prompt and waits for user to type "yes". In non-interactive mode it returns (false, error). If the user types anything other than "yes", it returns (false, nil). Only returns (true, nil) on "yes".

func FormatString

func FormatString(t MessageType, m Message) string

FormatString returns Output as string in certain format

func FormatStringWithTrans

func FormatStringWithTrans(t MessageType, m MessageWithTranslation) string

FormatStringWithTrans returns Output as string in certain format supporting multi languages

func JSONString

func JSONString(out interface{}) string

JSONString returns json string for message

func NewError

func NewError(code ErrorCode, info string, pre error) error

NewError and returns golang error that contains Error Message ErrorCode can pass zero only when previous error is always a format error that contains non-zero error code. ErrorCode passes 0 means that I want to use previous error's code rather than override it. If there is no previous error, newInfo should not be empty.

func PrintError

func PrintError(err error) error

PrintError prints Error Message in format, only used at top layer of a command

func PrintInfo added in v2.3.6

func PrintInfo(info string)

PrintInfo prints an informational line (e.g. "Blockchain Node: ...") that is suppressed in quiet mode.

func PrintQuery

func PrintQuery(query string)

PrintQuery prints query message in format

func PrintResult

func PrintResult(result string)

PrintResult prints result message in format

func RequireInteractive added in v2.3.6

func RequireInteractive(prompt string) error

RequireInteractive returns an error if non-interactive mode is set. Use this to guard interactive prompts (fmt.Scanf, etc.).

Types

type ConfirmationMessage

type ConfirmationMessage struct {
	Info    string   `json:"info"`
	Options []string `json:"options"`
}

ConfirmationMessage is the struct of an Confirmation output

func (*ConfirmationMessage) String

func (m *ConfirmationMessage) String() string

type ErrorCode

type ErrorCode int

ErrorCode is the code of error

const (
	// UndefinedError used when an error cat't be classified
	UndefinedError ErrorCode = iota
	// UpdateError used when an error occurs when running update command
	UpdateError
	// RuntimeError used when an error occurs in runtime
	RuntimeError
	// NetworkError used when an network error is happened
	NetworkError
	// APIError used when an API error is happened
	APIError
	// ValidationError used when validation is not passed
	ValidationError
	// SerializationError used when marshal or unmarshal meets error
	SerializationError
	// ReadFileError used when error occurs during reading a file
	ReadFileError
	// WriteFileError used when error occurs during writing a file
	WriteFileError
	// FlagError used when invalid flag is set
	FlagError
	// ConvertError used when fail to converting data
	ConvertError
	// CryptoError used when crypto error occurs
	CryptoError
	// AddressError used if an error is related to address
	AddressError
	// InputError used when error about input occurs
	InputError
	// KeystoreError used when an error related to keystore
	KeystoreError
	// ConfigError used when an error about config occurs
	ConfigError
	// InstantiationError used when an error during instantiation
	InstantiationError
	// CompilerError used when an error occurs when using the solidity compiler
	CompilerError
)

type ErrorMessage

type ErrorMessage struct {
	Code ErrorCode `json:"code"`
	Info string    `json:"info"`
}

ErrorMessage is the struct of an Error output

func (ErrorMessage) Error

func (m ErrorMessage) Error() string

Error implements error interface

func (*ErrorMessage) String

func (m *ErrorMessage) String() string

type Message

type Message interface {
	String() string
}

Message is the message part of output

type MessageType

type MessageType int

MessageType marks the type of output message

const (
	// Result represents the result of a command
	Result MessageType = iota
	// Confirmation represents request for confirmation
	Confirmation
	// Query represents request for answer of certain question
	Query
	// Error represents error occurred when running a command
	Error
	// Warn represents non-fatal mistake occurred when running a command
	Warn
)

func (MessageType) MarshalJSON added in v2.3.6

func (t MessageType) MarshalJSON() ([]byte, error)

MarshalJSON marshals MessageType as a human-readable string

type MessageWithTranslation

type MessageWithTranslation interface {
	String(args ...string) string
}

MessageWithTranslation is the message part of output supporting multi languages

type Output

type Output struct {
	MessageType            MessageType            `json:"messageType"`
	Message                Message                `json:"message"`
	MessageWithTranslation MessageWithTranslation `json:"messageWithTranslation,omitempty"`
}

Output is used for format output

type StringMessage

type StringMessage string

StringMessage is the Message for string

func (StringMessage) Query

func (m StringMessage) Query() string

Query prints query message

func (StringMessage) String

func (m StringMessage) String() string

func (StringMessage) Warn

func (m StringMessage) Warn() string

Warn prints warn message

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL