kongapp

package module
v0.18.1 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: MIT Imports: 5 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

kongapp

kongapp provides the repeated execution shell around a consumer-owned Kong command tree. It binds caller-owned context and streams, handles help without terminating an embedding process, and supports explicit post-parse initialization and teardown.

Applications retain ownership of command structs, flags, configuration, dependencies, signals, domain behavior, and exit policy:

ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt)
defer stop()

err := kongapp.Execute(ctx, os.Args[1:], kongapp.Streams{
    In: os.Stdin, Out: os.Stdout, Err: os.Stderr,
}, &commands, kongapp.Config[commandTree]{
    Name: "example",
    Options: []kong.Option{kong.Bind(service)},
})

Use Config.Initialize only for work that must happen after successful command selection. Help and version paths never call it. Return a cleanup function when initialization acquires resources.

Documentation

Overview

Package kongapp provides a small execution lifecycle for Kong command trees. Applications retain ownership of their command structs, dependencies, config, signal handling, and process exit policy.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Execute

func Execute[T any](
	ctx context.Context,
	args []string,
	streams Streams,
	tree *T,
	cfg Config[T],
) (err error)

Execute parses and runs a consumer-owned Kong command tree. args excludes the process name. The caller owns cancellation, streams, dependency bindings, and conversion of returned errors into process exit statuses.

Types

type Cleanup

type Cleanup func() error

Cleanup releases resources acquired by an Initializer.

type Config

type Config[T any] struct {
	Name        string
	Description string
	Vars        kong.Vars
	Help        kong.HelpOptions
	DefaultArgs []string
	Options     []kong.Option
	Initialize  Initializer[T]
}

Config defines infrastructure policy for one Kong command tree. Application and domain policy stay in the tree, injected options, and Initializer.

type Initializer

type Initializer[T any] func(
	ctx context.Context,
	parsed *kong.Context,
	tree *T,
	args []string,
) (Cleanup, error)

Initializer runs after successful parsing and before the selected command. The parsed command, populated command tree, and effective arguments are available for application-specific setup. Returning a Cleanup makes teardown part of the same lifecycle even when command execution fails.

type Streams

type Streams struct {
	In  io.Reader
	Out io.Writer
	Err io.Writer
}

Streams contains caller-owned process streams. Commands can request Streams as a Run method dependency; Kong's own output is routed to Out and Err.

Jump to

Keyboard shortcuts

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