render

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2026 License: MIT Imports: 17 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func SafeLine

func SafeLine(s string) string

Types

type DirectiveCount

type DirectiveCount struct {
	Directive string `json:"directive"`
	Count     int    `json:"count"`
}

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 Mode

type Mode int
const (
	Table Mode = iota
	JSON
)

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 New

func New(output string) *Printer

func (*Printer) ArchivedPageView

func (p *Printer) ArchivedPageView(body []byte)

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

func (p *Printer) DomainEnum(body []byte)

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

func (p *Printer) DryRun(payload any)

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) List

func (p *Printer) List(body []byte, fields ...string)

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

func (p *Printer) MacroDoc(body []byte)

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

func (p *Printer) MacroDocs(body []byte)

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

func (p *Printer) MacroScan(body []byte)

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

func (p *Printer) Malformed(status int, body []byte)

Malformed renders a non-ProblemDetail error response (e.g. Tomcat HTML 404).

func (*Printer) Message

func (p *Printer) Message(format string, a ...any)

func (*Printer) Page

func (p *Printer) Page(body []byte)

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

func (p *Printer) PageGet(body []byte, working bool, humanFields ...string)

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) PageRich

func (p *Printer) PageRich(body []byte)

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) Problem

func (p *Printer) Problem(pr *problem.Problem, suggestion string)

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

func (p *Printer) Raw(body []byte, humanFields ...string)

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

func (p *Printer) ReleaseNote(body []byte)

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.

type ProfileInfo

type ProfileInfo struct {
	BaseURL string `json:"baseUrl"`
	HasKey  bool   `json:"hasKey"`
}

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

Jump to

Keyboard shortcuts

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