cli

package
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2026 License: MIT Imports: 26 Imported by: 0

Documentation

Overview

Package cli implements the command-line interface for the True Markets CLI.

Index

Constants

View Source
const (
	BaseUSDC   = "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913"
	SolanaUSDC = "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"
)

USDC addresses per chain.

View Source
const (
	ExitSuccess = 0
	ExitGeneral = 1
	ExitUsage   = 2
	ExitAuth    = 3
	ExitAPI     = 4
	ExitNetwork = 5
)

Exit codes for the CLI.

Variables

View Source
var (
	Version   = "dev"
	CommitSHA = ""
)

Version and CommitSHA are set at build time via ldflags.

Functions

func ContextAPIKey

func ContextAPIKey(ctx context.Context) string

ContextAPIKey returns the resolved API key from the command context.

func ContextAuthToken

func ContextAuthToken(ctx context.Context) string

ContextAuthToken returns the resolved auth token from the command context.

func ContextHost

func ContextHost(ctx context.Context) string

ContextHost returns the resolved API host from the command context.

func ContextOutputJSON

func ContextOutputJSON(ctx context.Context) bool

ContextOutputJSON returns true if JSON output is requested.

func Execute

func Execute() int

Execute runs the CLI and returns an exit code.

Types

type CLIError

type CLIError struct {
	Code    int
	Message string
	Err     error
}

CLIError is a structured error with an exit code.

func (*CLIError) Error

func (e *CLIError) Error() string

func (*CLIError) Unwrap

func (e *CLIError) Unwrap() error

type KeyStore

type KeyStore struct {
	// contains filtered or unexported fields
}

KeyStore manages per-user API key files under ~/.config/truemarkets/keys/.

func NewKeyStore

func NewKeyStore() *KeyStore

NewKeyStore returns a KeyStore backed by ~/.config/truemarkets/keys/.

func (*KeyStore) LoadKey

func (ks *KeyStore) LoadKey(email string) (string, error)

LoadKey reads the private key for the given email.

func (*KeyStore) Path

func (ks *KeyStore) Path(email string) string

Path returns the file path for the given email's key.

func (*KeyStore) StoreKey

func (ks *KeyStore) StoreKey(email, privateKey string) error

StoreKey writes a private key to keys/{email} with mode 0600.

type TokenData

type TokenData struct {
	AccessToken  string    `json:"access_token"`
	RefreshToken string    `json:"refresh_token"`
	ExpiresAt    time.Time `json:"expires_at"`
	Email        string    `json:"email"`
}

TokenData represents stored token information.

type TokenManager

type TokenManager struct {
	// contains filtered or unexported fields
}

TokenManager handles token storage and retrieval.

func NewTokenManager

func NewTokenManager() *TokenManager

NewTokenManager creates a new token manager using ~/.config/truemarkets/credentials.json.

func (*TokenManager) ClearTokens

func (tm *TokenManager) ClearTokens() error

ClearTokens removes stored tokens.

func (*TokenManager) GetValidAccessToken

func (tm *TokenManager) GetValidAccessToken(ctx context.Context, host string) (string, error)

GetValidAccessToken returns a valid access token, refreshing if needed.

func (*TokenManager) LoadTokens

func (tm *TokenManager) LoadTokens() (*TokenData, error)

LoadTokens loads tokens from local storage.

func (*TokenManager) StoreTokens

func (tm *TokenManager) StoreTokens(tokens TokenData) error

StoreTokens saves tokens to local storage.

Directories

Path Synopsis
Package output provides utilities for formatting CLI output.
Package output provides utilities for formatting CLI output.

Jump to

Keyboard shortcuts

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