cmd

package
v0.0.0-...-9cd1a11 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2026 License: BSD-2-Clause Imports: 25 Imported by: 0

Documentation

Overview

Package cmd implements the CLI application to manage a portfolio.

Index

Constants

View Source
const (
	EnvPortfolioPath   = "PORTFOLIO_PATH"
	EnvDefaultCurrency = "PCS_DEFAULT_CURRENCY"
	EnvVerbose         = "PCS_VERBOSE"
)

Variables

View Source
var (
	Verbose = flag.Bool("v", false, "enable verbose logging")
)

Functions

func DecimalVar

func DecimalVar(f *decimal.Decimal, def string) decimalVar

func DecodeLedger

func DecodeLedger(query string) (*portfolio.Ledger, error)

DecodeLedger decodes the ledger from the application's default ledger file. If the file does not exist, it returns a new empty ledger.

func DecodeLedgers

func DecodeLedgers(query string) ([]*portfolio.Ledger, error)

DecodeLedgers decodes all ledgers from the portfolio path.

func EncodeTransaction

func EncodeTransaction(ledger *portfolio.Ledger, tx portfolio.Transaction) (portfolio.Transaction, error)

EncodeTransaction validates a transaction against the market data and existing ledger, then appends it to the ledger file.

func PortfolioPath

func PortfolioPath() string

PortfolioPath resolves the path to the portfolio directory. It follows this order of precedence: 1. --portfolio flag 2. PORTFOLIO_PATH environment variable 3. Current working directory (".")

func QuantityVar

func QuantityVar(f *portfolio.Quantity, def string) quantityVar

func Register

func Register(c *subcommands.Commander)

Register registers all the application's subcommands with the provided Commander. A main package will call Register() to set up the CLI.

func RegisterFetcher

func RegisterFetcher(protocol string, f Fetcher)

RegisterFetcher registers a fetcher for a specific protocol.

func RunExtension

func RunExtension(subcommand string, args []string) (bool, int)

RunExtension attempts to find and execute an external pcs-<subcommand> binary. It returns (true, exitCode) if an extension was found and executed, and (false, 0) if no extension was found or executed.

Types

type AssistCmd

type AssistCmd struct{}

AssistCmd is the subcommand for the AI assistant.

func (*AssistCmd) Execute

func (c *AssistCmd) Execute(ctx context.Context, f *flag.FlagSet, args ...interface{}) subcommands.ExitStatus

Execute executes the command.

func (*AssistCmd) Name

func (*AssistCmd) Name() string

Name returns the name of the command.

func (*AssistCmd) SetFlags

func (*AssistCmd) SetFlags(_ *flag.FlagSet)

SetFlags sets the flags for the command.

func (*AssistCmd) Synopsis

func (*AssistCmd) Synopsis() string

Synopsis returns a short-one line synopsis of the command.

func (*AssistCmd) Usage

func (*AssistCmd) Usage() string

Usage returns a long-form usage string.

type Fetcher

type Fetcher func(ctx context.Context, security portfolio.Security, from, to portfolio.Date) ([]portfolio.Transaction, error)

Fetcher is the interface that must be implemented by a market data provider. It fetches market data for a single security within a given date range.

Jump to

Keyboard shortcuts

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