Documentation
¶
Overview ¶
Package gxcli implements the gx command line tool.
Index ¶
- Constants
- func Delegate(args []string) (code int, ok bool)
- func Main(args []string, opts ...Option) int
- type Adapter
- type AdapterInfo
- type BuildInfo
- type BuildStep
- type BuildSteps
- type Command
- type Commands
- type Directive
- type DirectiveAttr
- type DirectiveUse
- type Directives
- type MCPTool
- type MCPTools
- type Option
- type Plugin
- type Registries
- type Registry
- type ThemePreset
- type ThemePresets
Constants ¶
const PluginAPI = 1
PluginAPI is the version of the plugin API of this Gx (REQ-PLG-05). A plugin says which version it was built for. A change of the API that breaks a plugin gets a new number.
const Version = "0.7.0"
Version is the Gx release this command line tool belongs to. `gx init` writes it into the go.mod of a new app.
Variables ¶
This section is empty.
Functions ¶
func Delegate ¶ added in v0.3.0
Delegate runs the gx command of the project of the working directory, when the project has one: the cmd/gx/main.go that gx init writes (REQ-PLG-02). That command has the plugins of the project compiled in, and the Gx version of the go.mod of the project. The global gx calls Delegate first, and runs its own Main when ok is false: the directory is in no project with a cmd/gx.
Types ¶
type Adapter ¶ added in v0.3.0
type Adapter interface {
Adapter() AdapterInfo
}
Adapter is the hook of a plugin that adds a hypermedia adapter.
type AdapterInfo ¶ added in v0.3.0
type AdapterInfo struct {
// Name is the value of the adapter key in gx.toml.
Name string
// Signals reports whether the adapter has client signals and client
// expressions.
Signals bool
// Modifiers are the event modifiers that an adapter with no signals
// can express, for example "debounce".
Modifiers []string
}
AdapterInfo is a hypermedia adapter that a plugin adds (REQ-PLG-01). The adapter itself is a gx.Adapter value of a package of the plugin, which the app gives to gx.Config. AdapterInfo is what the gx command must know: the name for the adapter key of gx.toml, and what the adapter can express, so the compiler reports a .gx file that the adapter cannot run (GX4006).
type BuildInfo ¶ added in v0.3.0
type BuildInfo struct {
// Root is the directory of the app.
Root string
}
BuildInfo is what a build step knows of the build.
type BuildStep ¶ added in v0.3.0
BuildStep is one step that a plugin adds to gx build. It runs after the generated code, the stylesheet and the island bundle are written, and before the Go build.
type BuildSteps ¶ added in v0.3.0
type BuildSteps interface {
BuildSteps() []BuildStep
}
BuildSteps is the hook of a plugin that adds steps to gx build.
type Command ¶ added in v0.3.0
type Command struct {
// Name is the word after gx, for example "deploy".
Name string
// Summary is the line of the command in gx help.
Summary string
// Run gets the arguments after the name and returns the exit code.
Run func(args []string) int
}
Command is one command that a plugin adds to gx.
type Commands ¶ added in v0.3.0
type Commands interface {
Commands() []Command
}
Commands is the hook of a plugin that adds commands to gx.
type Directive ¶ added in v0.3.0
type Directive struct {
// Name is the namespace and the name, for example "chartzoom:zoom".
Name string
// Transform returns the HTML attributes of one use. An error is a
// diagnostic at the place of the use.
Transform func(use DirectiveUse) ([]DirectiveAttr, error)
// Behavior is an ES module that a page with the directive loads, or
// nil. The module finds its elements by the attributes of Transform.
Behavior []byte
}
Directive is one directive that a plugin adds to .gx files (REQ-PLG-03). A directive is an attribute with the namespace of the plugin: chartzoom:zoom="2x". It runs at compile time: the compiler puts the attributes that Transform returns in the place of the directive. A directive cannot change the grammar, and it takes a static value.
type DirectiveAttr ¶ added in v0.3.0
type DirectiveAttr = compiler.DirectiveAttr
DirectiveAttr is one HTML attribute that a directive writes.
type DirectiveUse ¶ added in v0.3.0
type DirectiveUse = compiler.DirectiveUse
DirectiveUse is one use of a directive in a .gx file: the tag of the element and the static value. HasValue is false for the directive with no value.
type Directives ¶ added in v0.3.0
type Directives interface {
Directives() []Directive
}
Directives is the hook of a plugin that adds directives to .gx files.
type MCPTool ¶ added in v0.3.0
type MCPTool struct {
Name string
Description string
// InputSchema is the JSON Schema of the arguments: an object schema.
InputSchema json.RawMessage
// Call gets the JSON object of the arguments and returns the text of
// the answer.
Call func(ctx context.Context, args json.RawMessage) (string, error)
}
MCPTool is one tool that a plugin adds to the dev MCP server of gx mcp.
type MCPTools ¶ added in v0.3.0
type MCPTools interface {
MCPTools() []MCPTool
}
MCPTools is the hook of a plugin that adds tools to the dev MCP server.
type Option ¶ added in v0.3.0
type Option func(*config)
Option changes one run of Main.
func WithPlugins ¶ added in v0.3.0
WithPlugins gives Main the plugins of the project. Write it in the cmd/gx/main.go of the project:
os.Exit(gxcli.Main(os.Args[1:], gxcli.WithPlugins(chartzoom.Plugin())))
type Plugin ¶ added in v0.3.0
type Plugin interface {
// Name is the name of the plugin in messages, for example "chartzoom".
Name() string
// API is the version of the plugin API that the plugin was built for:
// return gxcli.PluginAPI of the Gx version that you tested with, as a
// number.
API() int
}
Plugin is a typed extension of the gx command of one project (REQ-PLG-01). A plugin is a Go value. The cmd/gx/main.go of the project gives it to Main with WithPlugins, so the Go compiler checks it and no code loads at run time (REQ-PLG-02).
A plugin adds to Gx through the hook interfaces that it also implements: Commands is one of them. A plugin cannot change the grammar of a .gx file: no hook takes part in the parse (REQ-PLG-05).
type Registries ¶ added in v0.3.0
type Registries interface {
Registries() []Registry
}
Registries is the hook of a plugin that adds component registries.
type Registry ¶ added in v0.3.0
type Registry struct {
Name string
// URL is an http or https address, or a directory.
URL string
// Headers are "name: value" strings for each request to the registry.
Headers []string
}
Registry is a component registry that a plugin adds. gx add @acme/button reads the registry with the name "acme". A registry of the same name in gx.toml goes before the registry of a plugin.
type ThemePreset ¶ added in v0.3.0
type ThemePreset struct {
Name string
// CSS is the content of app/theme.css for the theme.
CSS []byte
}
ThemePreset is one theme that a plugin adds. gx add theme:<name> writes its CSS as the theme of the app.
type ThemePresets ¶ added in v0.3.0
type ThemePresets interface {
ThemePresets() []ThemePreset
}
ThemePresets is the hook of a plugin that adds themes.