Documentation
¶
Overview ¶
Package render implements dual-mode output: a human table/text default and a stable machine-readable JSON mode (--output json). Data goes to stdout; errors and diagnostics go to stderr so `normatik ... | jq` stays clean.
Index ¶
- func SafeLine(s string) string
- type DirectiveCount
- type Mode
- type Printer
- func (p *Printer) ArchivedPageView(body []byte)
- func (p *Printer) DomainEnum(body []byte)
- func (p *Printer) DryRun(payload any)
- func (p *Printer) JSONDocument(body []byte)
- func (p *Printer) List(body []byte, fields ...string)
- func (p *Printer) MacroDoc(body []byte)
- func (p *Printer) MacroDocs(body []byte)
- func (p *Printer) MacroScan(body []byte)
- func (p *Printer) Malformed(status int, body []byte)
- func (p *Printer) Message(format string, a ...any)
- func (p *Printer) Page(body []byte)
- func (p *Printer) PageGet(body []byte, working bool, humanFields ...string)
- func (p *Printer) PageList(list *api.PagePageListResult)
- func (p *Printer) PagePropertyValues(body []byte)
- func (p *Printer) PageRich(body []byte)
- func (p *Printer) PageTypeMoveImpact(body []byte)
- func (p *Printer) Problem(pr *problem.Problem, suggestion string)
- func (p *Printer) Profiles(active string, profiles map[string]ProfileInfo)
- func (p *Printer) Raw(body []byte, humanFields ...string)
- func (p *Printer) ReleaseNote(body []byte)
- func (p *Printer) TrashedPageView(body []byte)
- type ProfileInfo
- type StyledText
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type DirectiveCount ¶
DirectiveCount is one macro/directive name and how often it occurs in a page's content.
func ScanDirectives ¶
func ScanDirectives(content string) []DirectiveCount
ScanDirectives counts content-macro usage in raw page markdown, by directive name, across all three forms:
- container (block): :::name{...} (a bare ":::" closes, not counted)
- leaf (block): ::name{...}
- inline: :name[...] / :name{...} (within a line)
Block-directive lines are counted once and not re-scanned for inline matches. Result is sorted by count desc, then name, for stable output.
type Printer ¶
type Printer struct {
Mode Mode
Out io.Writer
Err io.Writer
// Fields, when non-empty, overrides the derived columns in table mode
// (--fields id,name). It never affects JSON mode (verbatim contract).
Fields []string
// Quiet drops the header row and the pagination/meta footer in table mode.
Quiet bool
}
func (*Printer) ArchivedPageView ¶
ArchivedPageView renders GET /pages/admin/archive/{id} (ArchivedPageViewResult) in table mode: flattens the nested page object so name / page-type show as scalars. Nested page detail is "…" under Raw, so a dedicated renderer is needed. JSON mode dumps the body verbatim.
func (*Printer) DomainEnum ¶
DomainEnum renders a DomainEnumResult in table mode: id + name plus the allowed enum values, which the generic Raw printer would drop as a nested array (so the command looked broken — only `-o json` showed them). JSON mode dumps the body verbatim so the machine-readable contract is unchanged.
func (*Printer) DryRun ¶
DryRun prints a resolved write payload that WOULD be sent (pretty JSON on stdout) followed by a "no changes were saved" note on stderr. Used by the --dry-run property preview so an agent can inspect the exact form the CLI resolved without any write ever happening. The note lives on stderr so `normatik ... --dry-run -o json | jq` still sees only the payload.
func (*Printer) JSONDocument ¶ added in v1.0.0
JSONDocument writes a JSON document to stdout in both table and json mode.
func (*Printer) List ¶
List renders a list response — either a Page<X> envelope (content[] + paging) or a bare JSON array — as a table in table mode, or verbatim in JSON mode. fields selects/orders the columns; empty derives identifying columns from the first row. Nested objects/arrays are skipped as columns (use --output json).
func (*Printer) MacroDoc ¶
MacroDoc renders one macro's documentation (GET /content-macros/{name}/docs): name + form/module, summary, the examples one per line, and an attribute table (default '-' when the attribute has none). JSON mode dumps the body verbatim.
func (*Printer) MacroDocs ¶
MacroDocs renders the full macro knowledge base (GET /content-macros/docs): the preamble as an indented block, the shared filter syntax under its own heading, then a table of the enabled macros, closed with a per-macro details hint. JSON mode dumps the body verbatim so the machine contract is unchanged.
func (*Printer) MacroScan ¶
MacroScan renders a content-macro usage scan (macro -> pages). JSON mode dumps the full MacroScanResult verbatim; table mode lists the accessible pages and prints a restricted-access summary footer on stderr.
func (*Printer) Malformed ¶
Malformed renders a non-ProblemDetail error response (e.g. Tomcat HTML 404).
func (*Printer) Page ¶
Page renders a page composite (GET /public/v1/pages/{id} with all expand sections) as an ASCII document. JSON mode dumps the composite verbatim. It is fully nil-safe: missing maps/arrays/pointers/omitempty fields are simply skipped — never a panic.
func (*Printer) PageGet ¶
PageGet renders the GET /public/v1/pages/{id} detail for `pages get`: the identifying key/value summary (id, name, pageTypeName, parentId) on top, then the property values rendered with the SAME formatter as `pages render` (via the shared renderPropertiesSection → propValue). This makes the intuitive read-back show property values instead of an empty screen. JSON mode stays byte-identical to the raw composite body (only human/table mode formats). Nil-safe: a page with no property values shows a "(no property values)" note, never a panic.
When working is true, the property section is sourced from the WORKING revision (workingRevision.propertyValues) instead of the published values. On a workflow page a `pages update --property` lands on the working revision, but the default (published) read-back does not show it yet — so `--working` gives the agent a readable path to the value it just wrote. When there is no working revision the call falls back to the published (top-level) values with an explanatory note.
func (*Printer) PageList ¶
func (p *Printer) PageList(list *api.PagePageListResult)
PageList renders a Page<PageListResult> as a table (or raw JSON). It keeps the nicely-labelled default columns, but honours --fields (routing through the generic, schema-aware List so projection + unknown-field warnings work) and --quiet (dropping the header + footer).
func (*Printer) PagePropertyValues ¶ added in v1.0.0
PagePropertyValues renders GET /public/v1/pages/property-values. JSON mode re-serializes the body via rawDump. Table mode prints one row per page × property (PAGE ID, PAGE, PROPERTY, VALUE). A page without properties gets one row with PROPERTY "—" and an empty VALUE. --quiet drops the header.
func (*Printer) PageRich ¶
PageRich renders a page composite with macros resolved to ASCII layout. The rich output goes through a colorprofile.Writer at this single choke point: lipgloss v2 emits ANSI styling unconditionally, so the writer downsamples/strips it at the edge — a non-TTY destination (pipe, redirect, test buffer) gets plain text, NO_COLOR/CLICOLOR/CLICOLOR_FORCE are honoured, and a real terminal keeps its detected color profile. JSON mode stays the raw composite, untouched.
func (*Printer) PageTypeMoveImpact ¶ added in v1.0.0
PageTypeMoveImpact renders PageTypeMoveImpactResult. JSON mode dumps the full body. Table mode shows scalars plus at-risk descriptors with default ADOPT — the generic Raw printer would hide those lists as "…".
func (*Printer) Problem ¶
Problem renders a decoded ProblemDetail with hint + a synthesized next command. suggestion is the runnable "Try:" line (may be empty).
func (*Printer) Profiles ¶
func (p *Printer) Profiles(active string, profiles map[string]ProfileInfo)
Profiles renders the known environment profiles (name + base-URL + key presence), marking the active one. API keys are never shown. JSON mode emits {active, profiles: {name: {baseUrl, hasKey}}}.
func (*Printer) Raw ¶
Raw renders an arbitrary JSON body: pretty in JSON mode, or a flat key/value summary of selected fields in table mode.
func (*Printer) ReleaseNote ¶
ReleaseNote renders one release note (GET /public/v1/release-notes/{version}) as an ASCII document: a version + date header, then the markdown body flattened to ASCII through the SAME renderer `pages render --plain` uses (markdownToASCII). A release note carries no macroData, so the plain markdown route — not the rich macro-resolving one — is the correct analog. JSON mode dumps the detail record verbatim. Nil-safe: a missing body renders "(no content)", never a panic.
func (*Printer) TrashedPageView ¶ added in v1.0.0
TrashedPageView renders GET /pages/admin/trash/{id} (TrashedPageViewResult) in table mode: flattens the nested page object so name / page-type show as scalars. Trash is reasonless — only deletedAt and parentId sit next to page. JSON mode dumps the body verbatim.
type ProfileInfo ¶
ProfileInfo is the per-profile view for `auth list`: the base-URL plus whether the OS keychain holds a key for it. It never carries key material.
type StyledText ¶
type StyledText string
StyledText marks ANSI styling generated by the CLI after all dynamic content has been sanitized. It is the only Message argument that bypasses filtering.
func Styled ¶
func Styled(s string) StyledText