argparse

package
v0.0.0-...-470aecf Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package argparse provides reusable Go types for the carapace-spec-argparse JSON schema. The Python scraper (scrape.py) emits JSON matching these types; the ToSpecCommand method converts them into carapace-spec command.Command values that can be marshaled to YAML.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Command

func Command(data []byte) (command.Command, error)

Command is a convenience wrapper that parses JSON and returns a spec Command.

Types

type Argument

type Argument struct {
	Name     string   `json:"name"`
	Options  []string `json:"options"`
	Help     string   `json:"help"`
	Required bool     `json:"required"`
	Choices  []string `json:"choices"`
	Type     string   `json:"type"`
	Nargs    string   `json:"nargs"`
	Default  any      `json:"default"`
	Metavar  string   `json:"metavar"`
	IsBool   bool     `json:"is_bool"`
}

Argument is a single flag/argument in the JSON schema.

func (Argument) ToFlag

func (a Argument) ToFlag() command.Flag

ToFlag converts an Argument to a carapace-spec Flag.

type Cli

type Cli struct {
	Name    string `json:"name"`
	Version string `json:"version"`
}

Cli holds metadata about the scraped CLI.

type FlatCmd

type FlatCmd struct {
	Description string     `json:"description"`
	Arguments   []Argument `json:"arguments"`
	Group       string     `json:"group"`
}

FlatCmd is a single command in the flat command dict (keyed by space-separated path).

type GroupInfo

type GroupInfo struct {
	Help   string               `json:"help"`
	Groups map[string]GroupInfo `json:"groups"`
}

GroupInfo describes a command group in the JSON schema.

type Spec

type Spec struct {
	Cli      Cli                  `json:"cli"`
	Commands map[string]FlatCmd   `json:"commands"`
	Groups   map[string]GroupInfo `json:"groups"`
}

Spec is the top-level JSON schema emitted by scrape.py.

func ParseJSON

func ParseJSON(data []byte) (Spec, error)

ParseJSON parses scrape.py JSON output and returns a Spec.

func (Spec) ToSpecCommand

func (s Spec) ToSpecCommand() command.Command

ToSpecCommand converts the entire Spec into a carapace-spec Command tree. The root command contains global flags and all top-level subcommands.

Jump to

Keyboard shortcuts

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