Documentation
¶
Overview ¶
Package cli defines and parses PDFConcat's command-line grammar and describes it as structured help. It performs no filesystem access and writes no output: Parse turns arguments into a typed Command or a *UsageError, and Help returns the documentation of a command as data.
Index ¶
Constants ¶
const ( // RootHelpBytes bounds root discovery output. RootHelpBytes = 2 << 10 // CommandHelpBytes bounds task-specific command help. CommandHelpBytes = 4 << 10 )
helpKind is the Kind of every help document.
const ( // NameBuild assembles a PDF. NameBuild Name = "build" // NameCheck validates a job without creating a PDF. NameCheck Name = "check" // NameReport queries a saved report. NameReport Name = "report" // NameSchema prints a JSON Schema. NameSchema Name = "schema" // NameVersion prints version information. NameVersion Name = "version" // NameHelp prints help. NameHelp Name = "help" // FormatJSON is compact JSON, the default. FormatJSON Format = 0 // FormatText is human-readable text. FormatText Format = 1 // ProgressAuto retains interactive text with quiet redirected stderr. ProgressAuto ProgressMode = "auto" // ProgressJSON requests machine observations on stderr. ProgressJSON ProgressMode = "json" // ProgressNone disables optional observations. ProgressNone ProgressMode = "none" // PlanNone is the absence of instructions: report, schema, version, and help commands. PlanNone PlanSource = 0 // PlanFile is --plan FILE. PlanFile PlanSource = 1 // PlanStdin is --plan -. PlanStdin PlanSource = 2 // PlanInline is --plan-json JSON. PlanInline PlanSource = 3 // PlanOperands is a direct sequence of PDF paths and --blank. PlanOperands PlanSource = 4 // SchemaPlan is the schema command's name for the plan schema. SchemaPlan = "plan" // SchemaReport is the schema command's name for the saved-report schema. SchemaReport = "report" // SchemaResponse describes every structured command response. SchemaResponse = "response" )
const ( CodeMissingCommand report.Code = "usage_missing_command" CodeUnknownCommand report.Code = "usage_unknown_command" CodeCommandNotFirst report.Code = "usage_command_not_first" CodeUnknownOption report.Code = "usage_unknown_option" CodeInapplicableOption report.Code = "usage_inapplicable_option" CodeDuplicateOption report.Code = "usage_duplicate_option" CodeMissingValue report.Code = "usage_missing_value" CodeDashValue report.Code = "usage_dash_value" CodeUnexpectedValue report.Code = "usage_unexpected_value" CodeEmptyValue report.Code = "usage_empty_value" CodeInvalidUTF8 report.Code = "usage_invalid_utf8" CodeInvalidValue report.Code = "usage_invalid_value" CodeInvalidJobs report.Code = "usage_invalid_jobs" CodeConflictingActions report.Code = "usage_conflicting_actions" CodePlanSourceConflict report.Code = "usage_plan_source_conflict" CodeMissingPlanSource report.Code = "usage_missing_plan_source" CodeBaseDirConflict report.Code = "usage_base_dir_conflict" CodeMissingOperand report.Code = "usage_missing_operand" CodeUnexpectedOperand report.Code = "usage_unexpected_operand" CodeStdinOperand report.Code = "usage_stdin_operand" CodeUnknownSchema report.Code = "usage_unknown_schema" )
Diagnostic codes of command-line failures. Codes are stable; messages are not. Report-query rules that the report package also states use that package's codes, so a rule has one code wherever it is caught.
Variables ¶
This section is empty.
Functions ¶
func UsageCodes ¶
UsageCodes lists every diagnostic code Parse can produce, in a stable order.
Types ¶
type Command ¶
type Command struct {
// Name is the command. A help request is NameHelp whatever way it was asked for.
Name Name
// PlanPath is the --plan file; set only for PlanFile.
PlanPath string
// PlanJSON is the --plan-json text; set only for PlanInline.
PlanJSON string
// BaseDir is --base-dir; set only for PlanStdin and PlanInline.
BaseDir string
// Output is -o/--output, relative to the working directory; empty when the plan names the output.
Output string
// FitTo is the optional portrait target, overriding the plan declaration.
FitTo assembly.FitTarget
Progress ProgressMode
// ReportPath is --report for build and check, relative to the working directory.
ReportPath string
// ReportFile is the saved report that the report command reads.
ExpectAttempt string
ReportFile string
// Part is --part, the id of one contribution.
Part string
// View is --view: "parts" or "diagnostics".
View string
// SchemaName is the schema command's operand: "plan", "report" or "response".
SchemaName string
// HelpFor is the command a help request is about; empty for the root help.
HelpFor Name
// Operands are the direct PDF paths and --blank directives in command-line order, for PlanOperands.
// Each Position is the operand's zero-based index in the arguments, excluding the executable.
Operands []assembly.Operand
// Page is --page, a 1-based output page; HasPage preserves explicit zero.
Page int64
// Offset and Limit page a View; HasOffset and HasLimit say whether they were given.
Offset int64
Limit int64
// Jobs is --jobs; 0 means unset, and an explicit value is at least 1.
Jobs int
// Format is the rendering requested with --format; JSON unless a valid --format text was given.
Format Format
// PlanSource selects which of PlanPath, PlanJSON, and Operands carries the instructions.
PlanSource PlanSource
// Details is --details: the complete result for build and check, full records for report.
Details bool
// Overwrite is --overwrite.
Overwrite bool
// HasPage, HasOffset and HasLimit distinguish a given 0 from an absent option.
HasPage, HasOffset, HasLimit bool
}
Command is a parsed command line. Only the fields that apply to Name are set.
func Parse ¶
Parse reads the arguments after the executable name. It returns a *UsageError for a rejected command line.
The grammar and numeric tokens are checked left to right. Report-request semantics are checked once all options are known. Help still rejects invalid values and conflicting selectors, but skips missing requirements (a plan source, a report file, or a selection required by details/paging). After a lone "--" every argument is a literal operand.
func (*Command) ReportRequest ¶ added in v0.2.0
ReportRequest adapts parsed option presence into the report package's pure request contract.
type HelpCommand ¶
HelpCommand is one line of the root help's command list.
type HelpDoc ¶
type HelpDoc struct {
Next *[]string `json:"next"`
ExecutableFrom string `json:"executable_from,omitempty"`
NextArgs []string `json:"next_args,omitempty"`
Templates []HelpTemplate `json:"templates,omitempty"`
// Kind is always "help".
Kind string `json:"kind"`
// Command is the command described; absent for the root help.
Command Name `json:"command,omitempty"`
Summary string `json:"summary"`
// Example illustrates command grammar; Next carries runtime executable authority.
Example string `json:"example"`
Usage []string `json:"usage"`
// Commands lists the commands; present only in the root help.
Commands []HelpCommand `json:"commands,omitempty"`
// Options lists exactly the options that apply.
Options []HelpOption `json:"options"`
Notes []string `json:"notes,omitempty"`
FormatVersion int `json:"format_version"`
NextOmitted bool `json:"next_omitted,omitzero"`
}
HelpDoc is the structured help of the root or of one command. Rendered as JSON it is the default help output; RenderText gives the human form of the same content.
type HelpOption ¶
type HelpOption struct {
Name string `json:"name"`
Short string `json:"short,omitempty"`
Value string `json:"value,omitempty"`
Summary string `json:"summary"`
}
HelpOption describes one option.
type HelpTemplate ¶ added in v0.2.0
HelpTemplate is a labeled argv recipe requiring caller-supplied paths.
type PlanSource ¶
type PlanSource uint8
PlanSource says where the instructions of a build or check come from.
type ProgressMode ¶ added in v0.2.0
type ProgressMode string
ProgressMode selects optional stderr observations for build and check.
type UsageError ¶
type UsageError struct {
// Command is the command being parsed; empty when none was recognized.
Command Name
// Diagnostics are the located problems, each with stage "usage".
Diagnostics []report.Diagnostic
// Format is how to render the failure: text only when a valid --format text came before the fault.
Format Format
}
UsageError reports a rejected command line. The process exits with status 2. Parsing stops at the first fault, so Diagnostics holds exactly that one problem.
func (*UsageError) Error ¶
func (e *UsageError) Error() string
Error formats the first diagnostic as "argv:N: message [code]".