cli

package
v1.0.1 Latest Latest
Warning

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

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

Documentation

Overview

Package cli is the user-facing surface of the tyche binary. It maps CLI verbs (`tyche init`, `tyche generate`, …) onto the pure use-case orchestrators in internal/app, and is the only package in the binary that depends on the CLI framework (github.com/alecthomas/kong). The servergen, clientgen, and server libraries never import this package, so embedding one of them in another tool does not pull in Kong.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Exit

func Exit(code int, err error) error

Exit returns ExitError wrapping err with the given exit code, so the subcommand Run methods can signal non-zero exits without printing the usage banner.

func Run

func Run(args []string) (code int, err error)

Run is the entry point. It parses args, runs the resolved command, and returns the exit code. main() in cmd/tyche calls this and exits the process with the result.

Types

type BuildCmd

type BuildCmd struct {
	Package  string   `arg:"" help:"Package to build (e.g. ./cmd/api)." default:""`
	Output   string   `help:"Output binary path." short:"o" default:""`
	Patterns []string `help:"Package patterns to generate codecs for before building." default:""`
}

BuildCmd is `tyche build`. It runs `go build` against a temporary copy of the project with codecs generated in place, so the working tree is never modified.

func (*BuildCmd) Run

func (c *BuildCmd) Run(g *GlobalFlags) error

type CLI

type CLI struct {
	Version    VersionCmd    `cmd:"" help:"Print the tyche version and exit."`
	Client     ClientCmd     `cmd:"" help:"Regenerate the typed client from a tyche OpenAPI spec."`
	Completion CompletionCmd `cmd:"" hidden:"" help:"Print shell completion script (bash|zsh|fish|powershell)."`
	GlobalFlags
	Init     InitCmd     `cmd:"" help:"Scaffold a tyche.json config file in the project root."`
	Build    BuildCmd    `cmd:"" help:"Build a package from a temporary generated worktree."`
	Run      RunCmd      `cmd:"" help:"Run a package from a temporary generated worktree."`
	Generate GenerateCmd `cmd:"" help:"Generate typed route codecs into the working tree."`
	Clean    CleanCmd    `cmd:"" help:"Remove generated route codec files from the working tree."`
	Test     TestCmd     `cmd:"" help:"Run tests from a temporary generated worktree."`
	Config   ConfigCmd   `cmd:"" help:"Inspect and validate the resolved tyche.json."`
}

CLI is the top-level Kong command tree. Every subcommand is a struct field whose type implements `Run(*GlobalFlags) error`. The struct tags drive help text, flag binding, env-var lookup, and argument validation. Kong resolves precedence: command line > struct default > env var.

type CleanCmd

type CleanCmd struct {
	Patterns []string `help:"Package patterns to clean (default: ./...)." default:""`
}

CleanCmd is `tyche clean`. It removes generated route codec files from the working tree.

func (*CleanCmd) Run

func (c *CleanCmd) Run(g *GlobalFlags) error

type ClientCmd

type ClientCmd struct {
	Spec       string `help:"Path to the OpenAPI JSON document (overrides tyche.json)." default:""`
	Out        string `help:"Output directory for the generated client module (overrides tyche.json)." default:""`
	Module     string `help:"Go module path for the generated client (overrides tyche.json)." short:"m" default:""`
	Package    string `help:"Package name for generated files (default: derived from module)." default:""`
	Go         string `help:"go directive for the generated go.mod (default: 1.22)." default:""`
	ClientName string `help:"Generated client type name (default: Client)." default:""`
	TypeNaming string `` /* 126-byte string literal not displayed */
}

ClientCmd is `tyche client`. It regenerates the typed Go client from the configured OpenAPI document.

func (*ClientCmd) Run

func (c *ClientCmd) Run(g *GlobalFlags) error

type CompletionCmd

type CompletionCmd struct {
	Shell string `arg:"" enum:"bash,zsh,fish,powershell" help:"Shell to generate completion for."`
}

CompletionCmd is `tyche completion <shell>`. It prints a shell completion script for the requested shell to stdout, suitable for `tyche completion bash > /etc/bash_completion.d/tyche` or `tyche completion zsh > "${fpath[1]}/_tyche"`.

func (*CompletionCmd) Run

func (c *CompletionCmd) Run(g *GlobalFlags) error

type ConfigCmd

type ConfigCmd struct {
	Show ConfigShowCmd `cmd:"" help:"Print the resolved tyche.json (path, values, source of each field)."`
}

ConfigCmd groups the `tyche config ...` subcommands. Currently there is only `show`, but the structure leaves room for `validate`, `path`, or `init-template` without growing the top-level namespace.

type ConfigShowCmd

type ConfigShowCmd struct {
	JSON bool `help:"Emit resolved config as JSON (shorthand for --format=json)."`
}

ConfigShowCmd is `tyche config show`.

func (*ConfigShowCmd) Run

func (c *ConfigShowCmd) Run(g *GlobalFlags) error

type ExitError

type ExitError struct {
	Err  error
	Code int
}

ExitError is the structured error type for command failures. The process main() inspects it to set the right exit code.

func (*ExitError) Error

func (e *ExitError) Error() string

func (*ExitError) Unwrap

func (e *ExitError) Unwrap() error

type ExitPanic

type ExitPanic struct {
	Code int
}

ExitPanic is the panic value Kong's Exit function uses to unwind out of Parse / Run without killing the process. main()'s recover() catches it and uses the embedded code as the exit status. It is exported so cmd/tyche can do the recover at the right boundary.

func (*ExitPanic) Error

func (e *ExitPanic) Error() string

type GenerateCmd

type GenerateCmd struct {
	Patterns []string `help:"Package patterns to generate codecs for (default: ./...)." default:""`
}

GenerateCmd is `tyche generate`. It writes typed route codecs into the working tree for the given package patterns.

func (*GenerateCmd) Run

func (c *GenerateCmd) Run(g *GlobalFlags) error

type GlobalFlags

type GlobalFlags struct {
	Config string `help:"Path to a tyche.json config file (overrides discovery)." short:"c" env:"TYCHE_CONFIG"`
	Root   string `help:"Project root (default: current directory)." short:"r" default:""`
	Format string `help:"Output format: human (default), json, or quiet." enum:"human,json,quiet" default:"human"`
	Quiet  bool   `help:"Suppress the 'using config ...' info line." short:"q"`
	// contains filtered or unexported fields
}

GlobalFlags are the flags inherited by every subcommand.

type InitCmd

type InitCmd struct {
	Module     string `help:"Go module path for the generated client (skips the prompt)." short:"m" default:""`
	Spec       string `help:"Path to the OpenAPI document (skips the prompt)." default:"./api/openapi.json"`
	TypeNaming string `` /* 126-byte string literal not displayed */
	Force      bool   `help:"Overwrite an existing tyche.json." short:"f"`
	Yes        bool   `help:"Skip prompts; require all answers via flags." short:"y"`
}

InitCmd is the `tyche init` command. It writes a starter tyche.json next to go.mod, prompting for the client module path when stdin is a TTY and --module was not given.

func (*InitCmd) Run

func (c *InitCmd) Run(g *GlobalFlags) error

Run implements the command. The Printer is used to emit informational lines; the actual write goes through app.Scaffold.

type RunCmd

type RunCmd struct {
	Package  string   `arg:"" help:"Package to run (e.g. ./cmd/api)." default:""`
	Patterns []string `help:"Package patterns to generate codecs for before running." default:""`
}

RunCmd is `tyche run`. It runs `go run` against a temporary copy of the project with codecs generated in place.

func (*RunCmd) Run

func (c *RunCmd) Run(g *GlobalFlags) error

type TestCmd

type TestCmd struct {
	Patterns []string `arg:"" optional:"" help:"Package patterns to test (default: ./...)."`
	Verbose  bool     `help:"Run tests in verbose mode (passes -v to go test)." short:"v"`
}

TestCmd is `tyche test`. It runs `go test` against a temporary copy of the project with codecs generated in place.

func (*TestCmd) Run

func (c *TestCmd) Run(g *GlobalFlags) error

type VersionCmd

type VersionCmd struct{}

VersionCmd is `tyche version`. It prints the binary's build identity and exits.

func (*VersionCmd) Run

func (c *VersionCmd) Run(g *GlobalFlags) error

Jump to

Keyboard shortcuts

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