app

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2026 License: MPL-2.0 Imports: 29 Imported by: 0

Documentation

Overview

Package app runs PDFConcat commands: it connects the parsed command line to plan decoding, resource capture, inspection, layout, assembly, report production and publication, and decides the outcome that every command prints and the process exits with.

Pipeline

A build or check runs these stages in order and stops at the first stage that fails, reporting every problem that stage found:

decode the job once (file, stdin, inline JSON, or command-line operands)
flatten it: resolve paths and appearance values, keeping every origin
check the destination and register every plan, font, source, output and report file, so that no
  file is used in two roles
capture fonts and load them (before any PDF is touched)
capture each distinct source into a private workspace and inspect the copy, with bounded concurrency
resolve page geometry; check retains only placement geometry, while build shapes and writes
  each distinct generated page immediately into the shared resource document
check: describe the layout in a report
build: assemble the sources and completed resource into a staged file, stage the report,
  recheck both destinations, publish the PDF and then the report, remove the workspace

Outcomes and exit codes

Every command ends in a report.Status: ok (0), invalid instructions (2), I/O, backend or publication failure (1), or interruption (130). Standard output carries a compact JSON summary by default, the complete report with --details, or the same content as text with --format text. A failure report requested with --report is written to a new file only until every input is known; afterwards --overwrite governs it exactly as it governs the PDF.

Publication

The PDF is published before the report. If the PDF is published and the report cannot be, the staged report stays at a recovery path, the outcome is a failure with published true, and the diagnostic gives a rebuild-free recovery command. A signal that arrives after the PDF is visible does not change the outcome: the result describes what was committed.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type App

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

App runs commands.

func New

func New(newEngine EngineFactory) *App

New returns an App that creates its engine with newEngine when a command first needs it.

func (*App) Execute

func (a *App) Execute(ctx context.Context, command *cli.Command, env Env) int

Execute runs a parsed command and returns the process exit code.

func (*App) Run

func (a *App) Run(ctx context.Context, args []string, env Env) int

Run parses args (without the executable name) and executes the command. It returns the process exit code.

type BuildInfo

type BuildInfo struct {
	Version    string
	Commit     string
	CommitDate string
}

BuildInfo is the release metadata of the executable.

func ResolveBuild

func ResolveBuild(version string, info *debug.BuildInfo) BuildInfo

ResolveBuild decides the release metadata of the executable. A version set at link time wins; otherwise the version comes from version.txt. Module pseudo-versions do not override the project version. The commit and its time come from the toolchain's version-control records; missing provenance is unknown. info may be nil.

type Engine

type Engine interface {
	// Inspect reads one captured source and reports its facts.
	Inspect(ctx context.Context, path string, target *pdfengine.PageSize) (pdfengine.SourceInfo, error)
	// Assemble writes and verifies the final document described by request.
	Assemble(ctx context.Context, request *pdfengine.AssembleRequest) error
}

Engine is the PDF capability the pipeline needs. pdfengine.Engine implements it; tests substitute a fake to inject failures at each stage.

type EngineFactory

type EngineFactory func() (Engine, error)

EngineFactory creates the engine on first use, so commands that never touch a PDF (help, version, schema, report) do not initialize one.

type Env

type Env struct {
	Stdin  io.Reader
	Stdout io.Writer
	// Stderr receives scratch-cleanup warnings and the committed state when Stdout is broken.
	Stderr io.Writer
	// NewProgress constructs a session only at the parsed build/check boundary.
	// The process owns native sink classification, transport lifetime and closure.
	NewProgress func(context.Context, cli.ProgressMode, string) *Progress
	// ProgressRecord retains idle exception capability after telemetry has joined.
	ProgressRecord      RecordWriter
	ProgressInterrupted func() bool
	ProgressSequence    func() uint64
	// WorkingDir is the absolute directory relative command-line paths resolve against.
	Executable string
	WorkingDir string
	Build      BuildInfo
	Arguments  []string
}

Env is everything a command may touch outside its arguments. Nothing in this package reads a process-global stream, directory or environment variable.

type Progress added in v0.2.0

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

Progress owns bounded scheduling and presentation for one attempt.

func NewProgress added in v0.2.0

func NewProgress(ctx context.Context, mode cli.ProgressMode, attempt string, writer RecordWriter) *Progress

NewProgress starts optional bounded presentation for an already selected sink. Main owns sink selection, native construction and final sink close.

func (*Progress) Interrupted added in v0.2.0

func (controller *Progress) Interrupted() bool

Interrupted reports an actual presentation failure, excluding unsent canceled updates.

func (*Progress) NextSequence added in v0.2.0

func (controller *Progress) NextSequence() uint64

NextSequence shares ordering with exceptional records after Stop.

func (*Progress) Observe added in v0.2.0

func (controller *Progress) Observe(milestone observation.Milestone)

Observe only merges bounded typed state. It never encodes or waits for I/O.

func (*Progress) Stop added in v0.2.0

func (controller *Progress) Stop()

Stop drains retained final observations and joins the sole presenter.

type RecordWriter added in v0.2.0

type RecordWriter interface {
	WriteRecord(ctx context.Context, record []byte) error
}

RecordWriter is the process-owned bounded native record transport. App observations do not call it; only the joined presentation worker does.

Jump to

Keyboard shortcuts

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