okapicli

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2026 License: MIT Imports: 14 Imported by: 5

Documentation

Index

Constants

View Source
const (
	// SIGINT is the interrupt signal
	SIGINT = syscall.SIGINT
	// SIGTERM is the termination signal
	SIGTERM = syscall.SIGTERM
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CLI

type CLI struct {
	// contains filtered or unexported fields
}

func Default added in v0.3.5

func Default() *CLI

Default creates a CLI manager with a default Okapi instance

func New

func New(o *okapi.Okapi, name ...string) *CLI

New creates a new CLI manager for the Okapi You can optionally provide a custom application name

func (*CLI) Bool

func (c *CLI) Bool(name, shorthand string, defaultValue bool, usage string) *CLI

Bool adds a boolean flag with optional shorthand

func (*CLI) Duration added in v0.3.5

func (c *CLI) Duration(name, shorthand string, duration time.Duration, usage string) *CLI

Duration adds a time.Duration flag with optional shorthand

func (*CLI) Float

func (c *CLI) Float(name, shorthand string, defaultValue float64, usage string) *CLI

Float adds a float64 flag with optional shorthand

func (*CLI) FromStruct added in v0.3.5

func (c *CLI) FromStruct(v interface{}) *CLI

FromStruct registers CLI flags from struct tags. Supported tags:

  • cli: flag name (required to register flag)
  • short: shorthand letter (optional)
  • desc: description text (optional)
  • env: environment variable name to read from (optional)
  • default: default value (optional; otherwise uses field's current value)

Supported types: string, int*, bool, float*

func (*CLI) Get

func (c *CLI) Get(name string) interface{}

Get retrieves a flag value by name

func (*CLI) GetBool

func (c *CLI) GetBool(name string) bool

GetBool retrieves a bool flag value

func (*CLI) GetDuration added in v0.3.5

func (c *CLI) GetDuration(name string) time.Duration

GetDuration retrieves a time.Duration flag value

func (*CLI) GetFloat

func (c *CLI) GetFloat(name string) float64

GetFloat retrieves a float64 flag value

func (*CLI) GetInt

func (c *CLI) GetInt(name string) int

GetInt retrieves an int flag value

func (*CLI) GetString

func (c *CLI) GetString(name string) string

GetString retrieves a string flag value

func (*CLI) Int

func (c *CLI) Int(name, shorthand string, defaultValue int, usage string) *CLI

Int adds an integer flag with optional shorthand

func (*CLI) LoadConfig

func (c *CLI) LoadConfig(path string, v interface{}) error

LoadConfig loads configuration from a JSON or YAML file into a struct.

func (*CLI) MustParse added in v0.3.5

func (c *CLI) MustParse() *CLI

func (*CLI) Okapi added in v0.3.5

func (c *CLI) Okapi() *okapi.Okapi

Okapi returns the underlying Okapi instance

func (*CLI) Parse added in v0.3.4

func (c *CLI) Parse() error

Parse is an alias for ParseFlags

func (*CLI) ParseFlags

func (c *CLI) ParseFlags() error

ParseFlags parses the command line flags

func (*CLI) Run

func (c *CLI) Run() error

Run starts Okapi using default options and waits for shutdown signals. It handles graceful shutdown automatically.

It is a shortcut for RunServer(nil)

func (*CLI) RunServer

func (c *CLI) RunServer(opts ...*RunOptions) error

RunServer starts Okapi and waits for shutdown signals. It handles graceful shutdown automatically

func (*CLI) String

func (c *CLI) String(name, shorthand, defaultValue, usage string) *CLI

String adds a string flag with optional shorthand

func (*CLI) WithConfig added in v0.3.5

func (c *CLI) WithConfig(cfg interface{}) *CLI

WithConfig registers CLI flags from struct tags. Supported tags:

  • cli: flag name (required to register flag)
  • short: shorthand letter (optional)
  • desc: description text (optional)
  • env: environment variable name to read from (optional)
  • default: default value (optional; otherwise uses field's current value)

Supported types: string, int*, bool, float*

type RunOptions

type RunOptions struct {
	// ShutdownTimeout is the maximum time to wait for graceful shutdown
	ShutdownTimeout time.Duration

	// Signals are the OS signals to listen for (defaults to SIGINT, SIGTERM)
	Signals []os.Signal

	// OnStart is called right before the server starts
	OnStart func()

	// OnStarted is called after the server starts successfully
	OnStarted func()

	// OnShutdown is called before shutdown begins
	OnShutdown func()
}

RunOptions configures the Run behavior

Jump to

Keyboard shortcuts

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