Documentation
¶
Overview ¶
Package botcli exposes the optional repo-driven Discord bot command layer.
Use this package when a downstream Cobra application should discover named bot scripts from one or more repositories and mount a `bots` subtree that supports inventory, inspection, ordinary jsverbs, and host-managed bot runs.
The public entrypoints are:
- BuildBootstrap(...) to resolve repositories from raw argv / env / defaults
- NewBotsCommand(...) to mount the repo-driven `bots` command tree
Runtime customization has a deliberate "smallest hook first" shape:
- Use WithAppName(...) when only the dynamic env prefix should change.
- Use WithRuntimeModuleRegistrars(...) when bot scripts or ordinary jsverbs just need extra Go-native require() modules such as `require("app")`.
- Use WithRuntimeFactory(...) only when ordinary jsverb runtime creation itself must change, for example custom module roots, require behavior, builder configuration, or a custom engine/runtime lifecycle.
If the custom runtime behavior must also affect discovery and host-managed bot runs, implement HostOptionsProvider on the runtime factory so the same choice contributes jsdiscord host options as well.
Index ¶
- Constants
- func NewBotsCommand(bootstrap Bootstrap, opts ...CommandOption) (*cobra.Command, error)
- func ScanBotRepositories(repos []Repository) ([]*jsverbs.Registry, error)
- type Bootstrap
- type BuildOption
- type CommandOption
- type DiscoveredBot
- type HostOptionsProvider
- type Repository
- type RuntimeFactory
- type RuntimeFactoryFunc
Constants ¶
const ( DefaultEnvVarName = "DISCORD_BOT_REPOSITORIES" DefaultRepoPath = "examples/discord-bots" )
const BotRepositoryFlag = "bot-repository"
Variables ¶
This section is empty.
Functions ¶
func NewBotsCommand ¶
func NewBotsCommand(bootstrap Bootstrap, opts ...CommandOption) (*cobra.Command, error)
NewBotsCommand builds the public repo-driven bot command tree from a bootstrap.
func ScanBotRepositories ¶
func ScanBotRepositories(repos []Repository) ([]*jsverbs.Registry, error)
ScanBotRepositories discovers bot entrypoint scripts in each repository and scans only those scripts for jsverbs metadata. This avoids treating helper libraries under bot directories as standalone verbs.
Types ¶
type Bootstrap ¶
type Bootstrap struct {
Repositories []Repository
}
func BuildBootstrap ¶
func BuildBootstrap(rawArgs []string, opts ...BuildOption) (Bootstrap, error)
BuildBootstrap resolves bot repositories using CLI > env > default precedence.
type BuildOption ¶
type BuildOption func(*buildOptions) error
BuildOption customizes public repository bootstrap construction.
func WithDefaultRepositories ¶
func WithDefaultRepositories(paths ...string) BuildOption
WithDefaultRepositories overrides the fallback repository paths.
func WithEnvironmentVariable ¶
func WithEnvironmentVariable(name string) BuildOption
WithEnvironmentVariable overrides the env var used for repository discovery.
func WithRepositoryFlagName ¶
func WithRepositoryFlagName(name string) BuildOption
WithRepositoryFlagName overrides the CLI flag name used during raw-argv pre-scan.
func WithWorkingDirectory ¶
func WithWorkingDirectory(dir string) BuildOption
WithWorkingDirectory controls how relative repository paths are resolved.
type CommandOption ¶
type CommandOption func(*commandOptions) error
func WithAppName ¶
func WithAppName(name string) CommandOption
WithAppName controls the env prefix used by dynamic Glazed bot commands.
func WithRuntimeFactory ¶
func WithRuntimeFactory(factory RuntimeFactory) CommandOption
WithRuntimeFactory overrides ordinary jsverbs runtime creation.
Use this only when WithRuntimeModuleRegistrars(...) is not enough and the runtime creation process itself must change, for example custom module roots, require behavior, builder configuration, or runtime lifecycle details.
If the same customization should also affect discovery and host-managed bot runs, implement HostOptionsProvider on the factory so it can contribute the matching jsdiscord host options as well.
func WithRuntimeModuleRegistrars ¶
func WithRuntimeModuleRegistrars(registrars ...engine.RuntimeModuleRegistrar) CommandOption
WithRuntimeModuleRegistrars appends custom runtime-scoped native module registrars.
This is the first hook to reach for when scripts just need extra Go-native require() modules and the default runtime construction is otherwise correct. Prefer this over WithRuntimeFactory(...) unless runtime creation itself must change.
type DiscoveredBot ¶
type DiscoveredBot struct {
Repository Repository
Descriptor *jsdiscord.BotDescriptor
}
func DiscoverBots ¶
func DiscoverBots(ctx context.Context, bootstrap Bootstrap, hostOpts ...jsdiscord.HostOption) ([]DiscoveredBot, error)
func ResolveBot ¶
func ResolveBot(selector string, discovered []DiscoveredBot) (DiscoveredBot, error)
func (DiscoveredBot) CommandNames ¶
func (b DiscoveredBot) CommandNames() []string
func (DiscoveredBot) Description ¶
func (b DiscoveredBot) Description() string
func (DiscoveredBot) EventNames ¶
func (b DiscoveredBot) EventNames() []string
func (DiscoveredBot) Name ¶
func (b DiscoveredBot) Name() string
func (DiscoveredBot) ScriptPath ¶
func (b DiscoveredBot) ScriptPath() string
func (DiscoveredBot) SourceLabel ¶
func (b DiscoveredBot) SourceLabel() string
func (DiscoveredBot) Validate ¶
func (b DiscoveredBot) Validate() error
type HostOptionsProvider ¶
type HostOptionsProvider interface {
HostOptions() []jsdiscord.HostOption
}
HostOptionsProvider lets a RuntimeFactory also contribute jsdiscord host options used for discovery and host-managed bot runs.
Implement this when runtime customization must stay consistent across all runtime touchpoints, not only ordinary jsverb execution.
type Repository ¶
type RuntimeFactory ¶
type RuntimeFactory interface {
NewRuntimeForVerb(ctx context.Context, registry *jsverbs.Registry, verb *jsverbs.VerbSpec) (*engine.Runtime, error)
}
RuntimeFactory customizes runtime creation for ordinary jsverb execution.
Implement this only when the default runtime construction is not sufficient. If you only need extra native require() modules, prefer WithRuntimeModuleRegistrars(...).