clicmdv1
import clicmdv1 "pocketone.dev/ext/contracts/cli/commands/v1"
Package clicmdv1 is the cli.commands/v1 contract: the `pocketone` command tree. Each command path ("remote restore to") has at most one provider. Every operation of every wire contract linked into the binary is a command by default, under `remote` (Generated); an extension replaces one by providing the same path, or adds its own:
clicmdv1.Contract.Provide(app, clicmdv1.Command{Path: "remote rehash", Short: "...", Run: ...})
Mount builds the tree once the app's contracts are sealed. Two extensions providing one path are a startup error until pocketone.yaml picks one (`providers: {cli.commands/v1: {"remote rehash": rehasher}}`).
Source: ext/contracts/cli/commands/v1.
Variables
var Contract = extkit.NewKeyedContract[Command]("cli.commands/v1", func(c Command) string { return c.Path })
Contract is cli.commands/v1, keyed by command path.
Functions
Mount
func Mount(app core.App, root *cobra.Command)
Mount adds app's commands to root: every provided cli.commands/v1 command (replacing a command already at its path), then the generated ones nothing provides and root doesn't already have. Call it once app's contracts are sealed (after the standard set's Register, or extkit.Setup).
PathOf
func PathOf(id extkit.ContractID, op string) string
PathOf is the command path of a contract operation: `remote`, the contract id's words (without a leading "remote"), then the operation, with the last id word dropped from its front: restore/v1's restore_to is "remote restore to", remote/v1's status is "remote status", mail.suppression/v1's check is "remote mail suppression check".
Types
Command
type Command struct {
Path string // the words after the binary's name: "remote restore to"
Use string // its arguments as help shows them ("<name> <url>"); "" for none
Short string
Long string
Args cobra.PositionalArgs // nil: any
Flags func(fs *pflag.FlagSet)
Run func(c *Ctx, args []string) error
// contains filtered or unexported fields
}
Command is one `pocketone` command.
Generated
func Generated() []Command
Generated is a command for every operation people call of every wire contract linked into the binary: flags from its input's fields (and --json for the whole input), the answer printed as JSON. Public operations that take or return a raw body (an unsubscribe page, a mail provider's webhook) are for browsers and services, not people, and get none.
CommandRef
type CommandRef struct {
Path string `json:"path"` // the words after the binary's name: "remote restore to"
Use string `json:"use"` // the arguments as help shows them
Short string `json:"short,omitempty"`
Long string `json:"long,omitempty"`
Aliases []string `json:"aliases,omitempty"`
Flags []FlagRef `json:"flags,omitempty"`
Runnable bool `json:"runnable"` // false: a group of subcommands
// Source says who answers it: "pocketbase" (PocketBase's own commands), "ext/<name>" (an extension),
// "contract:<id>" (generated from a contract's operation), "contracts/<id>" (a contract package's shared client),
// "main" (the binary itself); "" when it can't be told (a group).
Source string `json:"source,omitempty"`
}
CommandRef is one command, every subcommand listed by its full path.
ContractRef
type ContractRef struct {
ID string `json:"id"`
Prefix string `json:"prefix"` // /api/_c/<id>
Routed bool `json:"routed"` // its own API shape: no generated operations
Provider string `json:"provider,omitempty"`
Provided bool `json:"provided"`
Ops []OpRef `json:"ops,omitempty"`
}
ContractRef is a contract with an HTTP API.
Ctx
type Ctx struct {
context.Context
Cmd *cobra.Command
Out io.Writer
}
Ctx is a running command.
Ctx.Caller
func (c *Ctx) Caller(id extkit.ContractID) (*extkit.Caller, error)
Caller calls contract id on the command's remote.
Ctx.Flags
func (c *Ctx) Flags() *pflag.FlagSet
Flags are the command's flags.
Ctx.Remote
func (c *Ctx) Remote() (*remoteclient.Client, error)
Remote opens the remote the command talks to: --remote (a name or URL), else the project's default remote, with its saved login (or the CI token). With no login it still returns the client, unauthenticated, so public operations work and the rest fail with the remote's own "sign in first".
FieldRef
type FieldRef struct {
Name string `json:"name"` // in the JSON body / MCP arguments
Flag string `json:"flag"` // the command's flag, without "--"
Type string `json:"type"` // string, bool, int, float, time, strings, json
}
FieldRef is one field of an operation's input.
FlagRef
type FlagRef struct {
Name string `json:"name"`
Shorthand string `json:"shorthand,omitempty"`
Type string `json:"type"`
Default string `json:"default,omitempty"`
Usage string `json:"usage,omitempty"`
}
FlagRef is one flag.
JSRef
type JSRef struct {
Extension string `json:"extension"`
Types string `json:"types"`
}
JSRef is what one extension adds to an app's JS API (pb_hooks and page code): its TypeScript declarations, as they go into the app's types.d.ts. Extension "contracts" is extkit's: the contracts' action hooks and types open to JS.
OpRef
type OpRef struct {
Name string `json:"name"`
Desc string `json:"desc,omitempty"`
Method string `json:"method"`
REST string `json:"rest"` // METHOD's path: /api/_c/<id>/<path>
Scope string `json:"scope"`
Out string `json:"out"` // json, stream or raw
RawIn bool `json:"rawIn,omitempty"`
Command string `json:"command,omitempty"` // the pocketone command; "" for raw public operations
Tool string `json:"tool,omitempty"` // the MCP tool; "" for uploads and downloads
ReadOnly bool `json:"readOnly"`
Input []FieldRef `json:"input,omitempty"`
}
OpRef is one operation and the ways to call it.
Reference
type Reference struct {
Global []FlagRef `json:"global"` // the root's persistent flags, which every command takes
Commands []CommandRef `json:"commands"`
Contracts []ContractRef `json:"contracts"`
JS []JSRef `json:"js,omitempty"`
}
Reference is the binary's command tree and the HTTP APIs and MCP tools of every contract linked into it, as `pocketone reference --json` prints it. pocketone.dev's CLI, REST and MCP references and each contract's and extension's "Commands and APIs" section are generated from it (site/sync).
BuildReference
func BuildReference(app core.App, root *cobra.Command) Reference
BuildReference describes root's command tree and the contract APIs linked into the binary, with their providers on app.
Questions and comments
Comments are a GitHub Discussions thread; sign in with GitHub to post.