cobra

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package cobra adapts conductor to cobra-based CLIs: one call wires themed help, shell completions, standard flags, version output and update notifications onto an existing root command, mirroring the conventions of clib's cli/cobra package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func UpdateCommand

func UpdateCommand(app *conductor.Runtime) *cobralib.Command

UpdateCommand returns the standard self-update subcommand. It dispatches on App.Updater's install method (brew, goinstall or github); tools distributed another way provide their own update command instead.

func VersionCommand

func VersionCommand(app *conductor.Runtime) *cobralib.Command

VersionCommand returns the standard `version` subcommand.

Types

type Flags

type Flags struct {
	Verbose bool
	Quiet   bool
	Color   clog.ColorMode
}

Flags are the standard persistent flags: verbosity and color. New registers them on the root command's persistent flag set and applies them to clog in the chained PersistentPreRunE.

func (*Flags) ConductorFlags

func (f *Flags) ConductorFlags() conductor.Flags

ConductorFlags implements conductor.FlagSource.

func (*Flags) Register

func (f *Flags) Register(fs *pflag.FlagSet)

Register adds --verbose/-v, --quiet/-q and --color to fs.

type Option

type Option func(*Program)

Option configures New.

func WithExitCode

func WithExitCode(fn func(error) int) Option

WithExitCode maps command errors to exit codes; see conductor.ExitCode.

func WithGenerator

func WithGenerator(fn func(*complete.Generator)) Option

WithGenerator customises the completion generator before completion actions run, e.g. to add dynamic argument specs.

func WithSections

func WithSections(opts ...clibcobra.SectionsOption) Option

WithSections configures the help section builder.

func WithUpdateCommand

func WithUpdateCommand() Option

WithUpdateCommand adds the standard Homebrew `update` subcommand.

func WithVersionCommand

func WithVersionCommand() Option

WithVersionCommand adds the standard `version` subcommand.

type Program

type Program struct {
	Runtime    *conductor.Runtime
	Root       *cobralib.Command
	Completion *clibcobra.Completion
	Flags      *Flags
	// contains filtered or unexported fields
}

Program is the assembled cobra CLI. All fields are exported and may be customised between New and Program.Run.

func New

func New(app *conductor.Runtime, root *cobralib.Command, opts ...Option) *Program

New wires conductor onto root: identity defaults from the App, themed help, persistent standard flags, a -V/--version flag, completion flags, and a chained PersistentPreRunE that applies the standard flags and starts the update notification once the command is resolved. Add subcommands to root before or after New; the completion generator is built at Run time.

func (*Program) Generator

func (p *Program) Generator() *complete.Generator

Generator builds the completion generator from the assembled command tree.

func (*Program) Run

func (p *Program) Run(ctx context.Context, args []string) int

Run is the one-call happy path: completion preflight, execute, deferred update-hint flush, and exit code mapping. The caller passes the result to os.Exit.

Jump to

Keyboard shortcuts

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