Documentation
¶
Overview ¶
Package flag provides utilities for managing command flags with environment variable fallback support. It implements a priority system: flag value > environment variable > default value.
Index ¶
- Constants
- func GetPrivateKey(cmd *cobra.Command) (string, error)
- func GetRPCURL(cmd *cobra.Command) (string, error)
- func GetRequiredPrivateKey(cmd *cobra.Command) (string, error)
- func GetRequiredRPCURL(cmd *cobra.Command) (string, error)
- func MarkFlagsRequired(cmd *cobra.Command, flagNames ...string)
- func MarkPersistentFlagsRequired(cmd *cobra.Command, flagNames ...string)
- type BigIntValue
Constants ¶
const ( // RPCURL is the flag name for RPC URL RPCURL = "rpc-url" // RPCURLEnvVar is the environment variable name for RPC URL RPCURLEnvVar = "ETH_RPC_URL" // DefaultRPCURL is the default RPC URL when no flag or env var is set DefaultRPCURL = "http://localhost:8545" // PrivateKey is the flag name for private key PrivateKey = "private-key" // PrivateKeyEnvVar is the environment variable name for private key PrivateKeyEnvVar = "PRIVATE_KEY" )
Variables ¶
This section is empty.
Functions ¶
func GetPrivateKey ¶
GetPrivateKey retrieves the private key from the command flag or environment variable. Returns the flag value if set, otherwise the environment variable value, otherwise the default. Returns empty string and nil error if none are set.
func GetRPCURL ¶
GetRPCURL retrieves the RPC URL from the command flag or environment variable. Returns the flag value if set, otherwise the environment variable value, otherwise empty string. Validates the URL format if a non-empty value is provided and returns an error if validation fails. Returns empty string and nil error if no value is set.
func GetRequiredPrivateKey ¶
GetRequiredPrivateKey retrieves the private key from the command flag or environment variable. Returns an error if the value is not set or empty.
func GetRequiredRPCURL ¶
GetRequiredRPCURL retrieves the RPC URL from the command flag or environment variable. Returns the flag value if set, otherwise the environment variable value. Validates the URL format and returns an error if the value is not set, empty, or invalid.
func MarkFlagsRequired ¶
MarkFlagsRequired marks one or more regular flags as required and logs a fatal error if marking fails. This helper ensures consistent error handling across all commands when marking flags as required.
func MarkPersistentFlagsRequired ¶
MarkPersistentFlagsRequired marks one or more persistent flags as required and logs a fatal error if marking fails. This helper ensures consistent error handling across all commands when marking persistent flags as required.
Types ¶
type BigIntValue ¶
BigIntValue is a custom flag type for big.Int values. It implements the pflag.Value interface to enable using *big.Int with Cobra flags.
func (*BigIntValue) Set ¶
func (b *BigIntValue) Set(s string) error
Set parses a decimal string and sets the big.Int value.
func (*BigIntValue) String ¶
func (b *BigIntValue) String() string
String returns the decimal string representation of the big.Int value.
func (*BigIntValue) Type ¶
func (b *BigIntValue) Type() string
Type returns the type string for this flag value.