cli

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package cli provides the command-line interface for the batterdb application. It includes functionality for starting the server, outputting the OpenAPI specification, and handling various command-line options such as setting the port, enabling HTTPS, and persisting the database to disk.

The package uses the kong library for command-line parsing and integrates with the handlers package to manage the server service.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(args []string, opts ...kong.Option) (*kong.Context, error)

New initializes and parses the command-line arguments.

Types

type CLI

type CLI struct {
	Port     int32  `short:"p" default:"1205"        help:"Port to listen on."`
	Store    bool   `short:"s"                       help:"Persist the database to disk."`
	RepoFile string `          default:"${RepoFile}" help:"The file to persist the database to."`
	Secure   bool   `short:"S"                       help:"Enable HTTPS."`

	Server ServerCmd `default:"1" help:"Start the server." cmd:""`

	OpenAPI OpenAPICmd `help:"Output the OpenAPI specification version." cmd:"" optional:""`

	Version kong.VersionFlag `short:"v" help:"Show version."`
}

CLI defines the structure for the command-line interface, including options for port, persistence, repository file, and HTTPS, as well as commands for starting the server and outputting the OpenAPI specification.

func (*CLI) AfterApply

func (cmd *CLI) AfterApply(ctx *Ctx) error

AfterApply applies the command-line options to the context and initializes the service.

func (*CLI) Validate

func (cmd *CLI) Validate() error

Validate validates the command-line options.

type Ctx

type Ctx struct {
	*debug.BuildInfo

	io.Writer
	Stop chan os.Signal
	// contains filtered or unexported fields
}

type OpenAPICmd

type OpenAPICmd struct {
	Spec string `default:"3.1" help:"OpenAPI specification version." enum:"3.1,3.0.3"`
}

OpenAPICmd represents the command to output the OpenAPI specification.

func (*OpenAPICmd) Run

func (cmd *OpenAPICmd) Run(ctx *Ctx) error

Run outputs the OpenAPI specification to the context writer.

type ServerCmd

type ServerCmd struct {
}

ServerCmd represents the command to start the server.

func (*ServerCmd) Run

func (cmd *ServerCmd) Run(ctx *Ctx) error

Run starts the server service in a goroutine and blocks until an OS signal is received, then it cancels the server context and waits for the server to exit.

Jump to

Keyboard shortcuts

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