appcmd

package
v0.3.0-alpha.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 4, 2026 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Overview

Package appcmd provides consumer-owned application commands without exposing Modary lifecycle or Action handler internals.

Run accepts a fallible DefinitionProvider for runtime commands. Help, version, and invalid syntax use the pure Metadata in Options without invoking it. Serve and RunAction are lower-level entry points for an assembled Definition.

Stability: alpha. Until Modary reaches v1, exported Go APIs and command syntax may change between minor releases. Consumers should pin an exact module version and review release notes before upgrading.

Index

Constants

View Source
const (
	DefaultListenAddress       = "127.0.0.1:8080"
	DefaultShutdownTimeout     = 10 * time.Second
	DefaultReadHeaderTimeout   = 5 * time.Second
	DefaultReadTimeout         = 30 * time.Second
	DefaultWriteTimeout        = 30 * time.Second
	DefaultIdleTimeout         = 90 * time.Second
	DefaultMaxHeaderBytes      = 1 << 20
	MaximumHeaderBytes         = 16 << 20
	DefaultMaxActionInputBytes = action.MaxJSONDocumentBytes
	MaximumActionInputBytes    = action.MaxJSONDocumentBytes
)

Command and HTTP server defaults are bounded and local-listener safe.

Variables

View Source
var (
	ErrContextRequired = errors.New("command context is required")
	ErrUsage           = errors.New("invalid command usage")
	ErrCallbackPanic   = errors.New("application command callback panic")
)

Sentinel command errors support errors.Is classification.

Functions

func Run

func Run(ctx context.Context, args []string, provider DefinitionProvider, options Options) error

Run dispatches the consumer application command. Parsing, help, version, and usage failures are pure and do not construct a Definition or start Modules.

func RunAction

func RunAction(ctx context.Context, args []string, definition appkit.Definition, options Options) error

RunAction executes the Action subcommand with the same arguments accepted after "action" by Run. Parsing and input validation complete before Modules are started.

func Serve

func Serve(ctx context.Context, definition appkit.Definition, options Options) error

Serve starts the consumer Application and its explicitly supplied HTTP handler. Cancellation drains HTTP before Module resources are released.

Types

type CallbackPanicError

type CallbackPanicError struct {
	Operation string
}

CallbackPanicError reports a contained consumer callback panic without exposing the recovered value.

func (*CallbackPanicError) Error

func (err *CallbackPanicError) Error() string

Error describes the callback operation without exposing the panic value.

func (*CallbackPanicError) Unwrap

func (err *CallbackPanicError) Unwrap() error

Unwrap classifies the failure as ErrCallbackPanic, including for a typed-nil receiver.

type DefinitionProvider

type DefinitionProvider = appkit.DefinitionProvider

DefinitionProvider constructs the consumer's explicit application composition. Run invokes it once only for a command that needs Modules.

type HandlerFactory

type HandlerFactory func(context.Context, *appkit.Application) (http.Handler, error)

HandlerFactory constructs the complete consumer-owned HTTP mount after the Application is fully started. Serve invokes it once with the command context and it must honor cancellation and deadlines and return promptly after cancellation. Appcmd never mounts a transport implicitly.

type ListenerFactory

type ListenerFactory func(context.Context, string, string) (net.Listener, error)

ListenerFactory allows consumers to supply socket activation or a test listener while preserving appcmd's lifecycle ordering. Custom Accept errors fail closed; only the framework-owned default listener retains net/http's temporary-error retry policy. Custom Listener.Addr and accepted connections are cooperative data-plane extensions: Read, Write, address, and deadline methods must obey their net package contracts. The factory must honor its context and return promptly after cancellation.

type Options

type Options struct {
	// Metadata is the pure command identity used by Run for help and version.
	// The DefinitionProvider must return this exact value for serve and action.
	Metadata appkit.Metadata
	App      appkit.Options
	Handler  HandlerFactory
	// Process explicitly enables shared readiness probes and pre-shutdown
	// admission drain. The consumer still owns and mounts the probe handlers.
	Process       *processkit.Manager
	Listener      ListenerFactory
	ListenAddress string
	// Stdin is closed only when a command context is canceled while an Action
	// input is being read from "-". Close must be safe concurrently with Read
	// and must unblock it; ownership otherwise remains with the consumer.
	Stdin io.ReadCloser
	// Stdout and Stderr are trusted, cooperative dependencies. Write must
	// return; a context or shutdown timeout cannot interrupt a blocked Writer.
	Stdout io.Writer
	Stderr io.Writer
	// Logger receives bounded structured command lifecycle diagnostics. A nil
	// Logger uses a JSON handler backed by Stderr.
	Logger              *slog.Logger
	ShutdownTimeout     time.Duration
	MaxActionInputBytes int64
	Server              ServerOptions
}

Options contains consumer policy for application and command execution. All zero values have local-development-safe defaults.

type ServerOptions

type ServerOptions struct {
	ReadHeaderTimeout time.Duration
	ReadTimeout       time.Duration
	WriteTimeout      time.Duration
	IdleTimeout       time.Duration
	MaxHeaderBytes    int
}

ServerOptions configures the public HTTP server without exposing it to the application lifecycle.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL