cli

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Version = "dev"

Version is the kbot build version. It defaults to "dev" and can be overridden at link time with -X on this package's Version symbol.

Functions

func CloseOutput

func CloseOutput(f *os.File, path string)

CloseOutput closes f when it was opened from a real path; it is a no-op for the shared os.Stdout handle.

func EmbeddedPalette

func EmbeddedPalette() (*pal.Palette, error)

EmbeddedPalette returns the embedded Total Annihilation palette parsed through the pal package. Shared by pal/sct/fnt/tnt commands that need a default palette when the caller doesn't supply one.

func HPIInputPath

func HPIInputPath(args []string, stream bool) (path string, cleanup func(), err error)

HPIInputPath resolves an archive path from args or stdin. When stream is true (or no args), stdin is spooled to a temp file because the HPI reader requires random-access I/O. The caller must invoke the returned cleanup function to remove the temp file.

func MD5Hex

func MD5Hex(data []byte) string

MD5Hex returns the lowercase hex MD5 digest of data. Round-trip commands use it to compare byte-for-byte fidelity between original and re-encoded assets.

func OpenContextVFS

func OpenContextVFS(explicit string) (*filesystem.VirtualFileSystem, string, error)

OpenContextVFS mounts a TA / TA: Kingdoms install as a virtual filesystem so commands can resolve bare filenames and virtual paths. Priority is the explicit --vfs flag, then the active kbot context. A nil VFS with a nil error means no root is available and the caller should fall back to plain local-disk handling.

func OpenOutput

func OpenOutput(path string) (*os.File, error)

OpenOutput returns a writable file for path, or os.Stdout when path is empty. Callers pair it with CloseOutput, which leaves stdout open.

func ParseColor

func ParseColor(s string, dflt color.RGBA) (color.RGBA, error)

ParseColor parses an #rrggbb or #rrggbbaa string into an RGBA value. An empty string yields dflt; "transparent" or "none" yields a fully transparent colour. The leading '#' is optional.

func PassFail

func PassFail(ok bool) string

PassFail renders a boolean as the "PASS"/"FAIL" labels round-trip summaries print.

func ReadInput

func ReadInput(args []string, stream bool) ([]byte, error)

ReadInput returns the raw bytes from either a file argument or stdin.

func ReportContextSource

func ReportContextSource(source string)

ReportContextSource prints a short note to stderr about where a path argument came from when it wasn't supplied explicitly. Pass the source returned by ResolveVFSPath.

func ResolveVFSPath

func ResolveVFSPath(explicit string) (path, source string, err error)

ResolveVFSPath returns the working directory a VFS-backed command should mount, in priority order: explicit user input, then the active kbot context (env override or persisted current). An empty return with a nil error means no path is available and the caller should produce its own "path required" diagnostic.

func TAKFeaturePalette

func TAKFeaturePalette(kingdom string, vfs *filesystem.VirtualFileSystem) (*gaf.Palette, error)

TAKFeaturePalette loads a TA:K kingdom's feature sprite palette from a VFS root. Feature GAFs are indexed against the palette embedded in palettes/<kingdom>_features.pcx — the sibling .pal carries a different (wrong-for-sprites) table, so the .pcx is authoritative here.

func TAKKingdomForTNT

func TAKKingdomForTNT(tntPath string) string

TAKKingdomForTNT reads the kingdom affinity from a TA:K map's sibling .ota (same directory, same base name). Returns "" if the .ota is absent or has no kingdom field — the caller decides how to handle an unknown kingdom.

func TAKKingdomPalette

func TAKKingdomPalette(kingdom string) (color.Palette, error)

TAKKingdomPalette returns the embedded TA: Kingdoms terrain/minimap palette for a kingdom name (aramon, taros, veruna, zhon, creon). TA:K bakes its minimap with the per-kingdom texture palette rather than a single global one.

func TAKPaletteForTNT

func TAKPaletteForTNT(tntPath, kingdomOverride string) (color.Palette, error)

TAKPaletteForTNT resolves the palette for a TA:K map: an explicit kingdom override wins, else the kingdom is read from the sibling .ota. Returns a clear error when neither is available.

func TNTPalette

func TNTPalette() (color.Palette, error)

TNTPalette returns the embedded TA palette as a color.Palette.

func WriteSARIF

func WriteSARIF(w io.Writer, driverName string, rules []SARIFRule, results []SARIFResult) error

WriteSARIF marshals a SARIF run with the kbot driver and writes it to the supplied writer with 2-space indentation. The driver name distinguishes which kbot subcommand produced the run so consumers can route results to the right rule catalogue.

func WriteTarget

func WriteTarget(data []byte, target string) error

WriteTarget writes data to the target path, or stdout when target is empty.

Types

type SARIFArtifactLocation

type SARIFArtifactLocation struct {
	URI string `json:"uri"`
}

type SARIFDriver

type SARIFDriver struct {
	Name           string      `json:"name"`
	InformationURI string      `json:"informationUri,omitempty"`
	Rules          []SARIFRule `json:"rules,omitempty"`
}

type SARIFLocation

type SARIFLocation struct {
	PhysicalLocation SARIFPhysicalLocation `json:"physicalLocation"`
}

type SARIFLog

type SARIFLog struct {
	Version string     `json:"version"`
	Schema  string     `json:"$schema"`
	Runs    []SARIFRun `json:"runs"`
}

type SARIFMessage

type SARIFMessage struct {
	Text string `json:"text,omitempty"`
}

type SARIFPhysicalLocation

type SARIFPhysicalLocation struct {
	ArtifactLocation SARIFArtifactLocation `json:"artifactLocation"`
	Region           *SARIFRegion          `json:"region,omitempty"`
}

type SARIFRegion

type SARIFRegion struct {
	StartLine   int `json:"startLine,omitempty"`
	StartColumn int `json:"startColumn,omitempty"`
	EndLine     int `json:"endLine,omitempty"`
	EndColumn   int `json:"endColumn,omitempty"`
}

SARIFRegion locates the diagnostic inside the artifact. Pointer fields keep them out of the JSON when the linter doesn't know a line/column (e.g. TNT diagnostics that apply to the whole file).

type SARIFResult

type SARIFResult struct {
	RuleID    string          `json:"ruleId"`
	Level     string          `json:"level"`
	Message   SARIFMessage    `json:"message"`
	Locations []SARIFLocation `json:"locations,omitempty"`
}

type SARIFRule

type SARIFRule struct {
	ID               string        `json:"id"`
	ShortDescription *SARIFMessage `json:"shortDescription,omitempty"`
	FullDescription  *SARIFMessage `json:"fullDescription,omitempty"`
}

func SARIFShortRule

func SARIFShortRule(id, short string) SARIFRule

SARIFShortRule is a one-line constructor — every kbot rule has a short description, hardly any have a long one.

type SARIFRun

type SARIFRun struct {
	Tool    SARIFTool     `json:"tool"`
	Results []SARIFResult `json:"results"`
}

type SARIFTool

type SARIFTool struct {
	Driver SARIFDriver `json:"driver"`
}

type VFSInputHit

type VFSInputHit struct {
	// Data is the file bytes.
	Data []byte
	// Source is a human-readable label for diagnostics ("./local-edit.tnt",
	// "vfs:maps/the pass.tnt", etc.).
	Source string
	// VirtualPath is the canonical lowercase VFS slot the file was found
	// at (empty when the file came from local disk).  Callers use this
	// to derive sibling files in the same backing store.
	VirtualPath string
}

VFSInputHit describes a successful path resolution.

func ResolveTSFInput

func ResolveTSFInput(arg, vfsRoot string, quiet bool) (*VFSInputHit, *filesystem.VirtualFileSystem, func(), error)

ResolveTSFInput locates a .tsf script the user named, mounting the active context's VFS so bare names under anims/ resolve. It returns the resolved input, the mounted VFS (for sibling lookups), and a cleanup function the caller must invoke.

func ResolveVFSInput

func ResolveVFSInput(arg string, vfs *filesystem.VirtualFileSystem, wantExt string, basenameDirs []string) (*VFSInputHit, error)

ResolveVFSInput finds a file the user asked for, trying the local filesystem first and then the supplied virtual filesystem. The matching logic mirrors what an OS-level path picker would do:

  • Absolute or cwd-relative paths that resolve to an on-disk file win immediately, regardless of any VFS mount.
  • Otherwise the argument is normalised (leading "./" stripped, backslashes converted to forward slashes, lowercased) and looked up in the VFS. Any segment equal to ".." is rejected — relative paths must stay inside the mounted root.
  • Bare basenames are searched against the VFS as a last resort, restricted to the directory prefix the caller supplies (e.g. "maps/") so we don't accidentally match a same-named file from a different category.

The wantExt and basenameDirs parameters narrow the search. Pass an empty wantExt to accept any extension; pass nil basenameDirs to disable the bare-basename fallback.

Jump to

Keyboard shortcuts

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