prompts

package
v1.18.1 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2026 License: BSD-3-Clause Imports: 20 Imported by: 11

Documentation

Overview

Package prompts provides interactive user prompts for CLI applications.

Index

Constants

View Source
const (
	Yes = "Yes"
	No  = "No"

	Add        = "Add"
	Del        = "Delete"
	Preview    = "Preview"
	MoreInfo   = "More Info"
	Done       = "Done"
	Cancel     = "Cancel"
	LessThanEq = "Less Than Or Eq"
	MoreThanEq = "More Than Or Eq"
	MoreThan   = "More Than"

	// Address formats
	PChainFormat = "P-Chain"
	CChainFormat = "C-Chain"
)
View Source
const EVMFormat = "evm"

EVMFormat represents the EVM address format

Variables

This section is empty.

Functions

func CaptureKeyAddress

func CaptureKeyAddress(
	prompt Prompter,
	goal string,
	keyDir string,
	getKey func(string) (string, error),
	network models.Network,
	addressFormat string,
) (string, error)

CaptureKeyAddress prompts the user to select a key address

func CaptureListDecision

func CaptureListDecision[T comparable](

	prompter Prompter,

	prompt string,

	capture func(prompt string) (T, error),

	capturePrompt string,

	label string,

	info string,
) ([]T, bool, error)

CaptureListDecision runs a for loop and continuously asks the user for a specific input (currently only `CapturePChainAddress` and `CaptureAddress` is supported) until the user cancels or chooses `Done`. It does also offer an optional `info` to print (if provided) and a preview. Items can also be removed.

func CheckChainAuthKeys added in v1.16.45

func CheckChainAuthKeys(chainAuthKeys []string, controlKeys []string, threshold uint32) error

CheckChainAuthKeys checks chain authorization criteria: - [chainAuthKeys] satisfy chain's [threshold] - [chainAuthKeys] is a subset of chain's [controlKeys]

func ConvertToAddress

func ConvertToAddress(addr string) (crypto.Address, error)

ConvertToAddress converts a string to a crypto.Address

func GetChainAuthKeys added in v1.16.45

func GetChainAuthKeys(prompt Prompter, controlKeys []string, threshold uint32) ([]string, error)

GetChainAuthKeys gets chain authorization keys from the user, as a subset of the chain's [controlKeys] with a len equal to the chain's [threshold].

func GetKeyOrLedger

func GetKeyOrLedger(prompter Prompter, goal string, keyDir string, includeEwoq bool) (bool, string, error)

GetKeyOrLedger prompts user to choose between key or ledger

func GetTestnetKeyOrLedger

func GetTestnetKeyOrLedger(prompt Prompter, goal string, keyDir string) (bool, string, error)

func PromptAddress

func PromptAddress(prompter Prompter, prompt string) (string, error)

PromptAddress prompts the user for an address

func PromptChain

func PromptChain(
	prompt Prompter,
	message string,
	blockchainNames []string,
	pChainEnabled bool,
	xChainEnabled bool,
	cChainEnabled bool,
	blockchainNameToAvoid string,
	blockchainIDEnabled bool,
) (bool, bool, bool, bool, string, string, error)

PromptChain prompts the user to select a chain

func PromptPrivateKey

func PromptPrivateKey(prompter Prompter, prompt string) (string, error)

PromptPrivateKey prompts the user for a private key

func ValidateAddress

func ValidateAddress(addr string) error

ValidateAddress validates an Ethereum address

func ValidateHexa added in v0.2.1

func ValidateHexa(input string) error

ValidateHexa validates hexadecimal string format

func ValidatePositiveInt added in v0.2.1

func ValidatePositiveInt(val int) error

ValidatePositiveInt validates that an integer is positive

func ValidateURLFormat

func ValidateURLFormat(input string) error

Types

type Comparator

type Comparator struct {
	Label string // Label that identifies reference value
	Type  string // Less Than Eq or More than Eq
	Value uint64 // Value to Compare To
}

func (*Comparator) Validate

func (comparator *Comparator) Validate(val uint64) error

type Prompter

type Prompter interface {
	CapturePositiveBigInt(promptStr string) (*big.Int, error)
	CaptureAddress(promptStr string) (crypto.Address, error)
	CaptureNewFilepath(promptStr string) (string, error)
	CaptureExistingFilepath(promptStr string) (string, error)
	CaptureYesNo(promptStr string) (bool, error)
	CaptureNoYes(promptStr string) (bool, error)
	CaptureList(promptStr string, options []string) (string, error)
	CaptureString(promptStr string) (string, error)
	CaptureGitURL(promptStr string) (*url.URL, error)
	CaptureURL(promptStr string) (string, error)
	CaptureStringAllowEmpty(promptStr string) (string, error)
	CaptureEmail(promptStr string) (string, error)
	CaptureIndex(promptStr string, options []any) (int, error)
	CaptureVersion(promptStr string) (string, error)
	CaptureDuration(promptStr string) (time.Duration, error)
	CaptureDate(promptStr string) (time.Time, error)
	CaptureNodeID(promptStr string) (ids.NodeID, error)
	CaptureID(promptStr string) (ids.ID, error)
	CaptureWeight(promptStr string) (uint64, error)
	CapturePositiveInt(promptStr string, comparators []Comparator) (int, error)
	CaptureUint64(promptStr string) (uint64, error)
	CaptureUint64Compare(promptStr string, comparators []Comparator) (uint64, error)
	CapturePChainAddress(promptStr string, network models.Network) (string, error)
	CaptureFutureDate(promptStr string, minDate time.Time) (time.Time, error)
	ChooseKeyOrLedger(goal string) (bool, error)
	CaptureValidatorBalance(promptStr string, availableBalance float64, minBalance float64) (float64, error)
	CaptureListWithSize(prompt string, options []string, size int) ([]string, error)
	CaptureFloat(promptStr string) (float64, error)
}

func NewPrompter

func NewPrompter() Prompter

NewPrompter creates a new prompter instance for interactive user input.

Directories

Path Synopsis
Package comparator provides comparison utilities for prompts.
Package comparator provides comparison utilities for prompts.
Package mocks provides mock implementations for testing prompts.
Package mocks provides mock implementations for testing prompts.

Jump to

Keyboard shortcuts

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