cobra

package
v0.0.13 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package cobra integrates chalk with github.com/spf13/cobra (or any other flag library exposing a pflag.FlagSet-shaped API) without importing cobra/pflag directly.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Commit

func Commit[T any](key string, val T) error

Commit persists val under key in the -cache directory. It is a no-op if -cache was not set. Init must have been called first.

func Recover

func Recover[T any](key string, def T) T

Recover loads a previously Commit-ed value for key from the -cache directory, or returns def if no cache is configured or the value is missing/unreadable. Init must have been called first.

Types

type FlagSet

type FlagSet interface {
	BoolVar(p *bool, name string, value bool, usage string)
	StringVar(p *string, name string, value string, usage string)
}

FlagSet is the subset of (*pflag.FlagSet) used by BindFlags to register flags. *pflag.FlagSet (e.g. cmd.PersistentFlags()) and stdlib *flag.FlagSet both satisfy this interface.

type Flags

type Flags struct {
	NoTTY, NoColor, Silent          bool
	InputDir, OutputDir, OutputFile string
	Extension, Cache                string
}

Flags holds chalk's standard CLI flags, populated once fs (passed to BindFlags) has been parsed.

func BindFlags

func BindFlags(fs FlagSet) *Flags

BindFlags registers chalk's standard flags on fs (e.g. cmd.PersistentFlags()) and returns a *Flags populated once fs is parsed:

f := chalkcobra.BindFlags(cmd.PersistentFlags())
// ... cmd.Execute() parses flags ...
r := f.Init()

func (*Flags) Init

func (f *Flags) Init() *chalk.Reporter

Init builds and installs a Reporter from the parsed flag values, and wires the checkpoint cache as checkpoint.Default(), used by Recover/Commit. Call from cmd's RunE/PersistentPreRunE, after cobra has parsed flags.

func (*Flags) Spool

func (f *Flags) Spool(args []string) (src spool.FileSystem, wlk spool.Walker, dst spool.FileSystem, err error)

Spool resolves the input/output file systems and walker from f, for use with github.com/fogfish/stream/spool. args are the positional file arguments (e.g. cmd.Flags().Args()).

func (*Flags) SpoolOptions

func (f *Flags) SpoolOptions() []opts.Option[spool.Spool]

SpoolOptions returns the github.com/fogfish/stream/spool options derived from f (currently: -extension), for use with spool.New.

Jump to

Keyboard shortcuts

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