Skip to content

CLI reference

mkunion is a tool dependency in go.mod, so every command runs through go tool:

go tool mkunion --help

mkunion watch

Generates union types and shapes for all packages under the given paths, runs go generate ./..., and keeps watching for changes:

go tool mkunion watch ./...
  • -g, --generate-only - generate once and exit (CI, scripts)
  • -G, --dont-run-go-generate - skip the automatic go generate ./... step
  • --type-registry - generate types_reg_gen.go type registries (default: true)
  • -v, --verbose - debug-level logging

mkunion

Generates code for specific files instead of whole packages:

go tool mkunion -i example/shape.go
  • -i, --input-go-file - Go file(s) to generate code for; falls back to $GOFILE, which makes it usable in //go:generate directives
  • -n, --name - union name(s) to generate
  • --type-registry - generate types_reg_gen.go type registry (default: true)
  • -v, --verbose - debug-level logging

mkunion shape-export

Exports Go types as TypeScript definitions for end-to-end type safety:

go tool mkunion shape-export --language typescript --output-dir ./output -i file.go
  • --lang, --language - output language (default: typescript)
  • -o, --output-dir - directory to write exported types to
  • -i, --input-go-file - Go file(s) to export; falls back to $GOFILE
  • -v, --verbose - debug-level logging

mkunion clean

Removes all mkunion-generated files, giving you a clean slate before regeneration:

go tool mkunion clean -n ./...   # preview what would be removed
go tool mkunion clean ./...      # remove for real
  • -n, --dry-run - list files that would be removed, without removing them
  • -v, --verbose - debug-level logging

A file is removed only when its name matches a generated pattern (*_union_gen.go, *_shape_gen.go, *_serde_gen.go, *_match_gen.go, types_reg_gen.go) and its first line is the mkunion header (// Code generated by mkunion. DO NOT EDIT.). Hand-written files and files from other generators (e.g. moq mocks) are left untouched.