- Repository:
git://eleglicity.com/go/optspec.git - Go import metadata:
https://eleglicity.com/go-modules/optspec/
Go import metadata is used by go get; it is not documentation and is intentionally blank in a browser.
Versionless commands resolve to the latest published release (v0.1.0):
go get eleglicity.com/go-modules/optspec
go install eleglicity.com/go-modules/optspec/cmd/optgen
Explicit @latest forms:
go get eleglicity.com/go-modules/optspec@latest
go install eleglicity.com/go-modules/optspec/cmd/optgen@latest
Versions
| Version | Commit | Go commands | Artifacts |
|---|---|---|---|
v0.1.0 (latest) |
abd59f89d01f1c998f058351af04ae5909e5e1ed |
go get eleglicity.com/go-modules/optspec@v0.1.0go install eleglicity.com/go-modules/optspec/cmd/optgen@v0.1.0 |
— |
Overview
optspec provides the reusable Go tooling that keeps Linux host scripts'
command-line interfaces consistent. The package models flags, positional
arguments, and subcommands and compiles them into shell argument parsing,
help text, and bash/zsh completions. The optgen CLI generates that
shell code from tagged Go structs.
optspec is the canonical module after the split from linux-scripts.
Install
Use the published Go module:
go get eleglicity.com/go-modules/optspec
Install the CLI:
go install eleglicity.com/go-modules/optspec/cmd/optgen@latest
Versions and checksums are injected by the catalog renderer from the release tag, not from this document.
Usage
Build an optspec.Options value and call optspec.Compile to get the
_processArgs_() and _help_() shell functions. Use
GenerateBashCompletion or GenerateZshCompletion for completion
scripts.
optgen reads a Go struct annotated with opt:, arg:, doc:, and
default: tags:
//go:generate optgen -type Options -o _options.sh --completion _completion.sh --shell bash
type Options struct {
Verbose bool `opt:"-v|--verbose" doc:"Verbose output"`
Config string `opt:"-c|--config" doc:"Config file" default:"/etc/my.conf"`
Name string `arg:"0" doc:"Name argument"`
}
Run optgen directly when go:generate is not convenient:
go run eleglicity.com/go-modules/optspec/cmd/optgen \
-type Options -f options.go -o _options.sh
Mechanism
optgen parses the target Go file with the standard go/parser and
go/ast packages, converts struct tags into optspec.Options, and
validates conflicting or malformed definitions before rendering.
optspec then emits deterministic shell code with delimiter markers so
generated regions can be replaced safely.
The package is self-hosting: cmd/optgen/internal/selfhost defines the
shell options struct with the same tags and uses optgen to regenerate
the project's option parsing.
Maintenance
Release one immutable tag at a clean HEAD; the catalog renderer reads the
version from that tag. Run GOWORK=off go test ./... at the repository
root and GOWORK=off go test ./... in this nested docs/site module
before publishing.
The documentation contract is owned by the site-catalog module;
widening it requires a new schema release.