cli

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package cli provides a zero-dependency subcommand framework shared across all MIST stack tools.

Each command gets its own flag set. Define flags on the command, then access parsed values in the Run handler:

cmd := &cli.Command{
    Name:  "serve",
    Usage: "Start the server",
}
cmd.AddStringFlag("addr", ":8080", "Listen address")
cmd.AddIntFlag("workers", 4, "Number of workers")
cmd.Run = func(cmd *cli.Command, args []string) error {
    addr := cmd.GetString("addr")
    workers := cmd.GetInt("workers")
    // ...
}
app.AddCommand(cmd)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type App

type App struct {
	Name    string
	Version string
	// contains filtered or unexported fields
}

App is the top-level CLI application.

func NewApp

func NewApp(name, version string) *App

NewApp creates an application with the built-in version command.

func (*App) AddCommand

func (a *App) AddCommand(c *Command)

AddCommand registers a subcommand.

func (*App) Execute

func (a *App) Execute(args []string) error

Execute parses the argument list and runs the matching subcommand.

type Command

type Command struct {
	Name  string
	Usage string
	Flags *flag.FlagSet
	Run   func(cmd *Command, args []string) error
	// contains filtered or unexported fields
}

Command is a single CLI subcommand with its own flag set.

func (*Command) AddBoolFlag

func (c *Command) AddBoolFlag(name string, value bool, usage string)

AddBoolFlag defines a boolean flag on this command.

func (*Command) AddFloat64Flag

func (c *Command) AddFloat64Flag(name string, value float64, usage string)

AddFloat64Flag defines a float64 flag on this command.

func (*Command) AddInt64Flag

func (c *Command) AddInt64Flag(name string, value int64, usage string)

AddInt64Flag defines an int64 flag on this command.

func (*Command) AddIntFlag

func (c *Command) AddIntFlag(name string, value int, usage string)

AddIntFlag defines an integer flag on this command.

func (*Command) AddStringFlag

func (c *Command) AddStringFlag(name, value, usage string)

AddStringFlag defines a string flag on this command.

func (*Command) GetBool

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

GetBool returns the parsed boolean flag value.

func (*Command) GetFloat64

func (c *Command) GetFloat64(name string) float64

GetFloat64 returns the parsed float64 flag value.

func (*Command) GetInt

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

GetInt returns the parsed integer flag value.

func (*Command) GetInt64

func (c *Command) GetInt64(name string) int64

GetInt64 returns the parsed int64 flag value.

func (*Command) GetString

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

GetString returns the parsed string flag value.

func (*Command) HasFlag

func (c *Command) HasFlag(name string) bool

HasFlag reports whether a flag with the given name is defined.

Jump to

Keyboard shortcuts

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