Documentation
¶
Overview ¶
Package cli provides common utilities for building command-line interfaces.
Index ¶
- Variables
- type CheckCmd
- type CommandError
- type CommandResult
- type Commands
- type DoctorCmd
- type ErrorRenderer
- type FileOrStdin
- func (f *FileOrStdin) Decode(ctx *kong.DecodeContext) error
- func (f *FileOrStdin) EnsureContents() error
- func (f *FileOrStdin) GetAbsoluteFilename() string
- func (f *FileOrStdin) GetSourceContent() ([]byte, error)
- func (f *FileOrStdin) LoadAST(ctx context.Context, ldr *loader.Loader) (*ast.AST, error)
- type FormatCmd
- type Globals
- type LexCmd
- type WebCmd
Constants ¶
This section is empty.
Variables ¶
var ( Version = "" CommitSHA = "" )
Functions ¶
This section is empty.
Types ¶
type CheckCmd ¶
type CheckCmd struct {
File FileOrStdin `help:"Beancount input filename (use '-' for stdin, or omit for stdin)." arg:"" optional:""`
}
type CommandError ¶ added in v0.7.0
type CommandError struct {
// contains filtered or unexported fields
}
CommandError signals a command failure with a specific exit code. Commands return this after handling all output (printing errors/warnings to stderr). Main centralizes exit handling instead of commands calling os.Exit directly.
func NewCommandError ¶ added in v0.7.0
func NewCommandError(exitCode int) *CommandError
NewCommandError creates a new CommandError with the given exit code.
func (*CommandError) Error ¶ added in v0.7.0
func (e *CommandError) Error() string
Error implements the error interface.
func (*CommandError) ExitCode ¶ added in v0.7.0
func (e *CommandError) ExitCode() int
ExitCode returns the exit code associated with this error.
type CommandResult ¶ added in v0.7.0
type CommandResult struct {
// ExitCode is the exit code to return to the OS.
// 0 indicates success, non-zero indicates failure.
ExitCode int
// Err is any error that occurred during command execution.
// Commands should populate this for non-zero exit codes.
Err error
}
CommandResult encapsulates the outcome of a command execution. It allows commands to return structured results instead of calling os.Exit directly, enabling better testability and centralizing exit handling in main().
func Failure ¶ added in v0.7.0
func Failure(err error) CommandResult
Failure returns a CommandResult indicating failure with the given error.
func Success ¶ added in v0.7.0
func Success() CommandResult
Success returns a CommandResult indicating successful execution.
type Commands ¶
type Commands struct {
Globals
Check CheckCmd `cmd:"" help:"Parse, check and realize a beancount input file."`
Doctor DoctorCmd `cmd:"" help:"Doctor utilities for debugging beancount files."`
Format FormatCmd `cmd:"" help:"Format a beancount file to align numbers and currencies."`
Web WebCmd `cmd:"" help:"Start a web server."`
}
type DoctorCmd ¶ added in v0.7.0
type DoctorCmd struct {
Lex LexCmd `cmd:"" help:"Show lexical tokens from a beancount file."`
}
DoctorCmd provides doctor utilities for debugging beancount files.
type ErrorRenderer ¶
type ErrorRenderer struct {
// contains filtered or unexported fields
}
ErrorRenderer renders errors with terminal styling and source context.
func NewErrorRenderer ¶
func NewErrorRenderer(source []byte) *ErrorRenderer
NewErrorRenderer creates a renderer with source content for context.
func (*ErrorRenderer) Render ¶
func (r *ErrorRenderer) Render(err error) string
Render formats a single error with styling and context.
func (*ErrorRenderer) RenderAll ¶
func (r *ErrorRenderer) RenderAll(errs []error) string
RenderAll formats multiple errors, separating them with blank lines.
type FileOrStdin ¶
FileOrStdin accepts either a file path or "-" for stdin. For stdin: Filename="<stdin>", Contents populated. For files: Filename set, Contents nil (read by loader).
func (*FileOrStdin) Decode ¶
func (f *FileOrStdin) Decode(ctx *kong.DecodeContext) error
Decode implements kong.MapperValue.
func (*FileOrStdin) EnsureContents ¶
func (f *FileOrStdin) EnsureContents() error
EnsureContents populates Contents from stdin if Filename is empty.
func (*FileOrStdin) GetAbsoluteFilename ¶
func (f *FileOrStdin) GetAbsoluteFilename() string
GetAbsoluteFilename returns the absolute path, or "<stdin>" for stdin.
func (*FileOrStdin) GetSourceContent ¶
func (f *FileOrStdin) GetSourceContent() ([]byte, error)
GetSourceContent returns source content for error formatting.
type FormatCmd ¶
type FormatCmd struct {
File FileOrStdin `help:"Beancount input filename (use '-' for stdin, or omit for stdin)." arg:"" optional:""`
CurrencyColumn int `` /* 130-byte string literal not displayed */
PrefixWidth int `help:"Width in characters for account names (auto if 0)." default:"0"`
NumWidth int `help:"Width for numbers (auto if 0)." default:"0"`
}
type Globals ¶
type Globals struct {
Telemetry bool `help:"Show timing telemetry for operations."`
}
Globals defines global flags available to all commands.
type LexCmd ¶ added in v0.7.0
type LexCmd struct {
File FileOrStdin `help:"Beancount input filename (use '-' for stdin, or omit for stdin)." arg:"" optional:""`
}
LexCmd shows lexical tokens from a beancount file.
type WebCmd ¶
type WebCmd struct {
File string `help:"Beancount ledger file to serve." arg:""`
Host string `help:"Host to bind to." default:"127.0.0.1"`
Port int `help:"Port to listen on." default:"8080"`
Create bool `help:"Automatically create file if it doesn't exist (no confirmation prompt)." short:"c"`
ReadOnly bool `help:"Enable read-only mode (no write operations allowed)." short:"r"`
Watch bool `help:"Watch files for changes and auto-reload." short:"w"`
}