spec

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2026 License: MIT Imports: 25 Imported by: 0

Documentation

Overview

Package spec implements `hadron spec ...` — an opinionated layer over the generic node/edge commands for maintaining product-spec nodes that follow the loc-as-citation convention: a spec's loc IS its citation number, <module>:<feature>:<rule>:<flow> (e.g. msg:010:02:03), and each colon level is a real parent/child node. The scheme, the frozen module codes, and the append-only number ledger are governed by a `register` node in the target memory. This package is general — it works on any memory following the convention, addressed by -m/--memory.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewCmdSpec

func NewCmdSpec(f *cmdutil.Factory) *cobra.Command

NewCmdSpec returns the `hadron spec` command group.

func SetEditorFuncForTest added in v0.3.0

func SetEditorFuncForTest(fn func(io *output.IOStreams, current string) (string, error)) func()

SetEditorFuncForTest replaces the editor seam and returns a restore func. Test-only: it lets sibling-package tests drive `spec edit`'s interactive path deterministically. The fake receives the current body and returns the edited one.

Types

type Citation

type Citation struct {
	Product string // 3 lowercase letters, "" in a flat corpus
	Module  string // 3 lowercase letters, "" for a bare product root
	Feature string // 3 digits, "" if absent
	Rule    string // 2 digits, "" if absent
	Flow    string // 2 digits, "" if absent
}

Citation is a parsed loc grammar. Flat (legacy): <module>[:<feature>[:<rule>[:<flow>]]] (e.g. msg:010:02). Product-rooted: <product>:<module>[:<feature>[:<rule>[:<flow>]]] (e.g. cli:cha:010:01).

func ParseCitation

func ParseCitation(s string) (Citation, error)

ParseCitation parses and validates a citation, returning a Usage error for any malformed segment. The rooting is inferred from segment 2's character class: a second alpha code ⇒ product-rooted (<product>:<module>:…); a 3-digit feature ⇒ flat (<module>:…). A lone alpha code parses as a flat module — callers that need a bare product root build the Citation directly.

func (Citation) ChildContract added in v0.3.0

func (c Citation) ChildContract() (Citation, bool)

ChildContract returns the reserved general-provisions contract one tier below this root — the "zero" sibling its children inherit: a product root's modules inherit <product>:gen, a module root's features inherit <module>:000, and a feature root's rules inherit <feature>:00. ok is false for a rule, a flow, or a citation that is itself a contract (those have no root children to provision). It is the dual of InheritedContractLoc, walked downward.

func (Citation) Format

func (c Citation) Format() string

Format re-emits the colon form, including the product when present.

func (Citation) InheritedContractLoc

func (c Citation) InheritedContractLoc() (Citation, bool)

InheritedContractLoc returns the general-provisions contract this citation inherits — the reserved "zero" sibling at its own tier: a rule inherits its feature's :00, a feature inherits its module's :000, and a product-rooted module inherits its product's :gen. ok is false for a flow, a flat module root, a bare product root, or a contract itself (contracts are inheritance sources, not sinks).

func (Citation) IsContract

func (c Citation) IsContract() bool

IsContract reports whether this citation is a reserved general-provisions contract — a feature's rule `00`, a module's feature `000`, or a product's module `gen`. Its siblings at the same tier inherit it.

func (Citation) Leaf added in v0.3.0

func (c Citation) Leaf() string

Leaf returns the deepest non-empty segment of the citation (the flow, rule, feature, module, or product). Used as a placeholder title for an ancestor node scaffolded by --new-path, until the author renames it.

func (Citation) Level

func (c Citation) Level() int

Level is 0 (bare product root) .. 4 (flow); module is 1, feature 2, rule 3. The product field does not shift levels — a product's module root is still level 1 — so existing level-keyed logic is unchanged.

func (Citation) Parent

func (c Citation) Parent() (Citation, bool)

Parent returns the citation one level up: flow→rule→feature→module, and a product-rooted module→its product root. A flat module root and a bare product root have no parent.

func (Citation) Seq added in v0.6.0

func (c Citation) Seq() (int, bool)

Seq derives the sibling sort order from the citation's deepest numeric segment (feature/rule/flow), so a spec node sorts among its siblings by citation and the portal can offer a "Next" (#40). ok is false for a module or bare product root, whose leaf is alphabetic and carries no numeric order.

func (Citation) String

func (c Citation) String() string

Jump to

Keyboard shortcuts

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