spec

package module
v1.5.1 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2026 License: MIT Imports: 29 Imported by: 14

README

carapace-spec

PkgGoDev GoReportCard documentation Coverage Status Packaging status

Define simple completions using a spec file (based on carapace).

The carapace-spec binary can be used to complete spec files, but carapace-bin is recommended as it supports a range of custom macros.

name: mycmd
description: my command
flags:
  --optarg?: optarg flag
  -r, --repeatable*: repeatable flag
  -v=: flag with value
persistentflags:
  --help: bool flag
completion:
  flag:
    optarg: ["one", "two\twith description", "three\twith style\tblue"]
    v: ["$files"]
commands:
- name: sub
  description: subcommand
  completion:
    positional:
      - ["$list(,)", "1", "2", "3"]
      - ["$directories"]

Generators

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ActionMacro

func ActionMacro(s string, a ...any) carapace.Action

ActionMacro completes given macro

func ActionSpec

func ActionSpec(path string) carapace.Action

ActionSpec completes a spec

func AddMacro

func AddMacro(s string, m Macro)

AddMacro adds a custom macro

func Codegen

func Codegen(cmd *cobra.Command) error

func NewAction

func NewAction(s []string) action

func Register

func Register(cmd *cobra.Command)

func Schema

func Schema() string

Types

type Command

type Command command.Command

func (Command) Codegen

func (c Command) Codegen() error

func (Command) ToCobra

func (c Command) ToCobra() *cobra.Command

func (Command) ToCobraE

func (c Command) ToCobraE() (*cobra.Command, error)

type Macro

type Macro struct {
	Name        string                       `json:"name"`
	Description string                       `json:"descriptions,omitempty"`
	Example     string                       `json:"example,omitempty"`
	Function    string                       `json:"function,omitempty"`
	Args        string                       `json:"args,omitempty"` // TODO shouldn't be necessary
	Macro       macro.Macro[carapace.Action] `json:"-"`              // TODO public?
}

TODO lots of overlapping `macro` terms. Macro[I|V|N] don't match the embedded generic `macro.Macro` well.

func MacroI

func MacroI[T any](f func(t T) carapace.Action) Macro

func MacroN

func MacroN(f func() carapace.Action) Macro

func MacroV

func MacroV[T any](f func(t ...T) carapace.Action) Macro

func (Macro) Parse

func (m Macro) Parse(s string) carapace.Action

func (Macro) Signature

func (m Macro) Signature() string

type MacroMap added in v1.5.0

type MacroMap macro.MacroMap[Macro]

func ScanMacros added in v1.5.0

func ScanMacros(pkgs ...string) (MacroMap, error)

TODO experimental - internal use

func (MacroMap) Format added in v1.5.0

func (m MacroMap) Format(pkg string) (string, error)

TODO experimental - internal use

Directories

Path Synopsis
cmd module
internal
pkg

Jump to

Keyboard shortcuts

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