Extensions and plugins
Add commands to nsgo, join its builds with plugins, and run the nsgo a module pins.
Extensions
Section titled “Extensions”A command nsgo does not know itself runs an extension, as git and cargo do, so a library built on NSGo can add its commands to nsgo’s:
- In a module,
nsgo X args…runsgo tool X args…when thego.modfound from the working directory upward declares a tool whose command name isXornsgo-X: the last element of its package path, before a major version such as/v2. The extension is then the version the module requires. - Otherwise it runs a program named
nsgo-XonPATH, which works outside a module too, such as before a project exists. - Otherwise
nsgoprints its usage and exits with status 2, as it does for any unknown command.
Built-in commands always win, and a name that is not letters, digits, - and _ runs nothing. The extension takes the arguments unchanged, nsgo’s standard input, output and error, and its environment with NSGO_EXTENSION=1 and NSGO_VERSION, the nsgo module’s version, which is empty for a build from a checkout; nsgo exits with the extension’s status. The usage, which nsgo help prints, lists the extensions found and where each comes from.
A library ships one as a Go main package whose directory is the command’s name, such as example.com/maps/cmd/maps for nsgo maps. An app adds it to its module with go get -tool example.com/maps/cmd/maps@latest, and go install example.com/maps/cmd/nsgo-maps@latest puts an nsgo-maps on PATH for use outside a module, which may run the same code as the tool.
Plugins
Section titled “Plugins”A plugin is a Go tool that joins nsgo build, nsgo dev, nsgo check and nsgo test, where an extension only adds a command: it adds files to the app’s Go builds and its web site, reloads files of its own in nsgo dev, checks what it owns and adds tests. NSGo TSX’s is one. An app adds it to its module, which pins its version as it pins nsgo’s, and enables it in nsgo.yaml by its package path, with the settings it reads:
go get -tool github.com/nsgo-dev/nsgo-tsx/cmd/nsgo-tsxplugins: github.com/nsgo-dev/nsgo-tsx/cmd/nsgo-tsx: limits: defaultA plugin’s name is its command name without a leading nsgo-, such as tsx, which names it in nsgo’s output. -plugin name.setting=value on nsgo build and nsgo dev sets one of its settings for a run, as -plugin tsx.limits=default, and its tool also runs as the extension nsgo <name>, as NSGo TSX’s signing commands run as nsgo tsx publish and the rest.
nsgo runs the plugin at each point with NSGO_PLUGIN naming it, a JSON request on standard input and a JSON response on standard output, the contract package github.com/nsgo-dev/nsgo/toolplugin defines; toolplugin.Handle answers it in a plugin’s main, which runs the plugin’s own commands otherwise. A plugin fails a step by exiting with a non-zero status, and nsgo shows what it wrote to standard error.
The module’s nsgo
Section titled “The module’s nsgo”An nsgo installed on PATH never builds a project with another version than the one the project pins. In a module whose go.mod declares the tool github.com/nsgo-dev/nsgo/cmd/nsgo at another version, nsgo first runs the module’s, go tool nsgo with the same arguments, which then resolves the built-in commands and extensions, and exits with its status. NSGO_DELEGATED=1 in its environment keeps it from doing the same again, and NSGO_NO_DELEGATE=1 runs the nsgo called instead. Outside a module, in one without the tool, in NSGo’s own module and at the same version, nothing changes. A built-in command newer than the pinned release, such as add in a module that pins 0.3.4, is not handed on: nsgo exits with status 1 and names the go get that brings it (Adding libraries). nsgo version says which one ran, such as nsgo v0.4.0 (the module's; called as v0.3.1).