urfave

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package urfave adapts a urfave/cli v3 command tree to a clink daemon.

Every clink consumer using urfave/cli otherwise writes the same file: build a fresh command tree per session, point its I/O at the session, neutralise urfave's process-global exit and error sinks so a bad command cannot kill the daemon or print into its console, prepend argv[0], translate cli.ExitCoder into clink.ExitError, and recover panics. None of that is application-specific, and getting any of it wrong fails quietly rather than loudly.

The consumer keeps only what is genuinely theirs — building the tree:

return urfave.Serve(ctx, conf, func(s clink.Session) *cli.Command {
    return rootCommand(s, commands)
})

This is a separate Go module: a subpackage would force urfave/cli onto every clink consumer, including those using cobra or no framework at all.

Index

Constants

This section is empty.

Variables

View Source
var ErrNilRoot = errors.New("urfave: newRoot returned nil")

ErrNilRoot is returned when newRoot yields a nil command.

View Source
var ErrPanic = errors.New("command panicked")

ErrPanic is returned to the client whose command panicked. The panic value and stack go to the panic handler (see WithPanicHandler), not to the client, so an application's internals do not leak into a user's terminal.

Functions

func Handler

func Handler(newRoot func(clink.Session) *cli.Command, opts ...Option) clink.Handler

Handler builds the clink.Handler that Serve runs. It is exported for applications that need to wrap it — dispatching empty args to a TUI before falling through to the command tree, for instance.

func Serve

func Serve(ctx context.Context, conf clink.Config, newRoot func(clink.Session) *cli.Command, opts ...Option) error

Serve runs a clink daemon that dispatches each session through an urfave command tree.

newRoot must return a fresh tree per call: urfave stores per-run state on the command (I/O writers, parsed flags) and handlers run concurrently, so a shared instance races and can leak one client's output into another's session.

Serve blocks until ctx is cancelled, like clink.Listen. Use Handler to build the handler yourself when a session needs handling that is not a command tree — an empty-args main TUI, say.

Types

type Option

type Option func(*options)

Option configures Serve and Handler.

func WithGlobalSinks

func WithGlobalSinks(keep bool) Option

WithGlobalSinks keeps urfave's process-global cli.OsExiter and cli.ErrWriter untouched. The default (false) neutralises both, which is what a daemon wants: cli.OsExiter would otherwise take the whole daemon down on a bad command, and cli.ErrWriter writes to the daemon's console instead of the client's terminal. Set this only if the application manages those globals itself.

func WithPanicHandler

func WithPanicHandler(fn func(ctx context.Context, reason any, stack []byte)) Option

WithPanicHandler replaces the default panic handler, which logs to slog.Default. Consumers that journal panics elsewhere can hook in here. The client still receives ErrPanic and exit code 1 regardless.

Jump to

Keyboard shortcuts

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