router

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2026 License: MIT Imports: 13 Imported by: 0

README

pkg/framework/router

Canonical command-routing contracts live here.

  • ParsedCommand is the framework-standard output from routing.
  • Structured parameter merge helpers for --set / --params live here.
  • The concrete cobra-backed CommandRouter is introduced in Phase 3.
  • Transitional parser package has been removed; test/programmatic parsing uses router.ParseInput.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ErrInvalidArgs

func ErrInvalidArgs(msg string) error

ErrInvalidArgs returns a user-category CLIError for invalid argument input. It is provided here so that callers (e.g. cliapp) do not need to import the full errors package just to construct a simple user error.

func MergeStructuredParams

func MergeStructuredParams(flags map[string]any, explicit map[string]any) (map[string]any, error)

MergeStructuredParams folds --params (JSON) and --set (key=value) into the flag set. Keys already present in explicit (i.e. the user passed a real CLI flag) take precedence and are left untouched.

Keys contributed by --params and --set are promoted into explicit so downstream steps that filter by ExplicitFlags treat them the same as a user-typed CLI flag.

explicit is mutated in place; callers should pass the same map they intend to use as ParsedCommand.ExplicitFlags.

Types

type CommandRouter

type CommandRouter struct {
	// contains filtered or unexported fields
}

func NewCommandRouter

func NewCommandRouter(manager *registry.RegistryManager, appName string) (*CommandRouter, error)

func (*CommandRouter) Build

func (r *CommandRouter) Build(executor func(*ParsedCommand) error) error

func (*CommandRouter) CurrentInput

func (r *CommandRouter) CurrentInput() *frameworkadapter.RawInput

func (*CommandRouter) Execute

func (r *CommandRouter) Execute(input *frameworkadapter.RawInput, executor func(*ParsedCommand) error) error

func (*CommandRouter) RootCommand

func (r *CommandRouter) RootCommand() *cobra.Command

func (*CommandRouter) Route

type ParsedCommand

type ParsedCommand struct {
	Node          *registry.CommandNode
	FullPath      []string
	Flags         map[string]any
	ExplicitFlags map[string]any
	Args          []string
	IsHelp        bool
	RawArgs       []string
	RawFlags      map[string]string
	Diagnostics   []RouteDiagnostic
}

func ParseInput

func ParseInput(reg *registry.Registry, input *frameworkadapter.RawInput) (*ParsedCommand, error)

ParseInput converts RawInput to ParsedCommand by resolving the command and parsing parameters. This is a helper function primarily used in tests and for programmatic command construction.

NOTE: In production CLI flows, parameter parsing is handled by cobra. This function is mainly for SDK/programmatic access and test scenarios.

type RouteDiagnostic

type RouteDiagnostic struct {
	Kind    string
	Token   string
	Message string
}

Jump to

Keyboard shortcuts

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