compat

package
v1.0.33 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2026 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NewGroupCommand = cobracmd.NewGroupCommand

NewGroupCommand delegates to cobracmd.NewGroupCommand for backward compatibility.

Functions

func ApplyBindings

func ApplyBindings(cmd *cobra.Command, bindings []FlagBinding)

func ApplyTransform

func ApplyTransform(value any, transform string, args map[string]any) (any, error)

ApplyTransform applies a named transform rule to a value. Supported transforms: iso8601_to_millis, csv_to_array, json_parse, json_parse_strict, enum_map, file_read, invert_bool, string_to_int64.

func BuildDynamicCommands

func BuildDynamicCommands(servers []market.ServerDescriptor, runner executor.Runner, detailsByID map[string][]market.DetailTool) []*cobra.Command

BuildDynamicCommands generates cobra commands from servers.json CLIOverlay metadata. Each server with non-skip CLIOverlay gets a top-level command with groups and tool overrides translated into subcommands with proper flag bindings and transforms.

detailsByID maps CLI server ID → []DetailTool from the MCP Detail API. When provided, tool Short/Long descriptions and typed flags are enriched from Detail API data.

Conversion rules reference: docs/mcp-to-cli-conversion.md

func CollectBindings

func CollectBindings(cmd *cobra.Command, bindings []FlagBinding, existing map[string]any) (map[string]any, error)

func MoveParam

func MoveParam(params map[string]any, from, to string)

func MustString

func MustString(params map[string]any, key string) (string, error)

func NewCuratedCommand

func NewCuratedCommand(route Route, runner executor.Runner) *cobra.Command

NewCuratedCommand creates a DirectCommand with override priority so it wins over auto-generated MCP overlay commands during command tree merging.

func NewDirectCommand

func NewDirectCommand(route Route, runner executor.Runner) *cobra.Command

func NewFallbackCommands

func NewFallbackCommands(runner executor.Runner) []*cobra.Command

func NewPublicCommands

func NewPublicCommands(runner executor.Runner) []*cobra.Command

func RegisterFallback

func RegisterFallback(factory CommandFactory)

func RegisterPublic

func RegisterPublic(factory CommandFactory)

func ServerEndpoints

func ServerEndpoints(servers []market.ServerDescriptor) map[string]string

ServerEndpoints extracts product ID → endpoint URL mapping from servers.

func ServerProductIDs

func ServerProductIDs(servers []market.ServerDescriptor) map[string]bool

ServerProductIDs extracts the set of product IDs from servers with CLI metadata.

Types

type CommandFactory

type CommandFactory func(runner executor.Runner) *cobra.Command

type FlagBinding

type FlagBinding struct {
	FlagName string
	Alias    string
	// Aliases are additional hidden flag names that map to the same MCP
	// parameter. Any of them being set satisfies Required, and the value
	// is resolved via firstChangedFlag(FlagName, Alias, Aliases...).
	// Mirrors cmdutil.ValidateRequiredFlagWithAliases / FlagOrFallback.
	Aliases []string
	// PipelineLocal, when true, marks this binding as CLI-side only — its
	// value is consumed by the pipeline executor (e.g. as an HTTP
	// download destination) and NOT forwarded to any MCP tool's params.
	PipelineLocal bool
	Short         string
	Property      string
	Kind          ValueKind
	Usage         string
	Required      bool
	// Default is the cobra-level flag default value as a string. Parsed
	// into the Kind-appropriate primitive at registration time. Empty
	// string keeps the existing zero-value default. This only affects
	// what cobra renders in --help (the "(default ...)" suffix); it does
	// NOT inject the value into MCP params on its own — CollectBindings
	// still gates writes by user-changed flags via firstChangedFlag.
	Default string
	// Positional binds this parameter to a positional CLI argument rather
	// than a --flag. PositionalIndex is the 0-based slot.
	Positional      bool
	PositionalIndex int
}

type Normalizer

type Normalizer func(cmd *cobra.Command, params map[string]any) error

type Route

type Route struct {
	Use      string
	Aliases  []string
	Short    string
	Long     string
	Example  string
	Hidden   bool
	Target   Target
	Bindings []FlagBinding
	// Pipeline, when non-empty, replaces the single-tool dispatch with a
	// multi-step orchestration. NewDirectCommand sees this and wires the
	// pipeline executor into RunE instead of the standard
	// invoke-then-output flow. See internal/compat/pipeline.go.
	Pipeline   []market.PipelineStep
	Normalizer Normalizer
	// OutputTransform, when non-nil, post-processes the MCP response payload
	// (rename / drop / columns) before the formatter emits it. Wired up from
	// CLIToolOverride.OutputFormat. See discovery-schema-v3 §2.5.
	OutputTransform func(map[string]any) map[string]any
	// RejectPositional forces cobra.NoArgs on the generated leaf when no
	// positional bindings exist, so stray positional tokens (e.g.
	// `dws contact label list unexpected`) exit non-zero. Sourced from
	// CLIToolOverride.RejectPositional. Ignored when the leaf already
	// declares positional bindings — their arity validator wins.
	RejectPositional bool
	// RequireTogether groups flag aliases that must all be set together (or
	// all left unset). Each inner slice produces one PreRunE cross-field
	// check. Sourced from CLIToolOverride.RequireTogether. Unknown flag
	// names are logged and skipped at command-build time (consistent with
	// applyFlagConstraints semantics).
	RequireTogether [][]string
}

type Target

type Target struct {
	CanonicalProduct string
	Tool             string
}

type ValueKind

type ValueKind string
const (
	ValueString      ValueKind = "string"
	ValueInt         ValueKind = "int"
	ValueFloat       ValueKind = "float"
	ValueBool        ValueKind = "bool"
	ValueStringSlice ValueKind = "string_slice"
	ValueIntSlice    ValueKind = "int_slice"
	ValueFloatSlice  ValueKind = "float_slice"
	ValueBoolSlice   ValueKind = "bool_slice"
	ValueJSON        ValueKind = "json"
)

Jump to

Keyboard shortcuts

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