cli

package
v1.0.38 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2026 License: Apache-2.0 Imports: 32 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	CatalogFixtureEnv    = "DWS_CATALOG_FIXTURE"
	CacheDirEnv          = "DWS_CACHE_DIR"
	PluginColdTimeoutEnv = "DWS_PLUGIN_COLD_TIMEOUT"
	DefaultMarketBaseURL = config.DefaultMCPBaseURL
)

Variables

This section is empty.

Functions

func NewMCPCommand

func NewMCPCommand(ctx context.Context, loader CatalogLoader, runner executor.Runner, engine *pipeline.Engine) *cobra.Command

func NewSchemaCommand

func NewSchemaCommand(loader CatalogLoader) *cobra.Command

func OverridePriority

func OverridePriority(cmd *cobra.Command) int

OverridePriority delegates to cobracmd.OverridePriority.

func ReadFileArg

func ReadFileArg(value string) (string, bool, error)

ReadFileArg reads the contents of a file referenced by the @filename syntax. Returns the original value unchanged if it does not start with "@" or is otherwise not a file-path-shaped value (e.g. "@所有人" is treated as plain text, not a path). Returns an error if the file cannot be read or exceeds the size limit.

Note: @- (stdin) is NOT handled here; use ResolveInputSource instead.

func ReadStdin

func ReadStdin() (string, error)

ReadStdin reads all data from stdin unconditionally (up to maxStdinSize). Use this when the caller has explicitly requested stdin via @-.

func ReadStdinIfPiped

func ReadStdinIfPiped() (string, error)

ReadStdinIfPiped reads all data from stdin if it is a pipe (not a terminal). Returns empty string if stdin is a terminal or has no data.

func ResolveInputSource

func ResolveInputSource(value string, flagName string, guard *StdinGuard) (string, error)

ResolveInputSource resolves a flag value that may reference an external input source. It supports three forms:

  • "@-" reads from stdin (requires StdinGuard claim)
  • "@<path>" reads from the named file
  • anything else returned unchanged

The flagName parameter is used only for error messages and StdinGuard tracking.

func SetOverridePriority

func SetOverridePriority(cmd *cobra.Command, priority int)

SetOverridePriority delegates to cobracmd.SetOverridePriority.

func StdinIsPipe

func StdinIsPipe() bool

StdinIsPipe reports whether stdin is a pipe (not a terminal). This is a non-consuming check — it only inspects file mode via stat.

func ValidateInputSchema

func ValidateInputSchema(params map[string]any, schema map[string]any) error

ValidateInputSchema performs strict local validation for MCP tool inputs. It enforces required/type/enum checks and rejects unknown properties by default.

Types

type CatalogDegraded added in v1.0.9

type CatalogDegraded struct {
	Reason      CatalogDegradedReason
	Hint        string
	ServerCount int // number of servers discovered (only set for runtime_all_failed)
}

CatalogDegraded is returned by EnvironmentLoader.Load when discovery fails for a diagnosable reason. Callers that need graceful degradation (e.g. the runtime runner) can check errors.As and fall back to an empty catalog; callers like the schema command can surface the hint.

func (*CatalogDegraded) Error added in v1.0.9

func (e *CatalogDegraded) Error() string

type CatalogDegradedReason added in v1.0.9

type CatalogDegradedReason string

CatalogDegradedReason identifies why catalog discovery returned empty.

const (
	DegradedUnauthenticated   CatalogDegradedReason = "unauthenticated"
	DegradedMarketUnreachable CatalogDegradedReason = "market_unreachable"
	DegradedRuntimeAllFailed  CatalogDegradedReason = "runtime_all_failed"
)

type CatalogLoader

type CatalogLoader interface {
	Load(context.Context) (ir.Catalog, error)
}

func CatalogLoaderFrom

func CatalogLoaderFrom(catalog ir.Catalog, err error) CatalogLoader

CatalogLoaderFrom creates a CatalogLoader that returns a pre-loaded catalog and error. This allows multiple consumers (schema command, MCP command tree) to share one discovery result.

type EnvironmentLoader

type EnvironmentLoader struct {
	LookupEnv func(string) (string, bool)
	// CatalogBaseURLOverride allows tests to redirect catalog discovery.
	CatalogBaseURLOverride string
	// DiscoveryTimeout overrides the default timeout for live registry discovery.
	// Zero means use defaultDiscoveryTimeout.
	DiscoveryTimeout time.Duration
	// AuthTokenFunc returns an access token for MCP discovery requests
	// (initialize, tools/list). When nil, discovery runs without auth.
	AuthTokenFunc func(context.Context) string
	// LoggerFunc returns a structured logger for discovery diagnostics.
	// Called lazily because the file logger may not be initialized at
	// construction time (it's set up during PersistentPreRunE).
	LoggerFunc func() *slog.Logger
}

func NewEnvironmentLoader

func NewEnvironmentLoader() EnvironmentLoader

func (EnvironmentLoader) Load

type FixtureLoader

type FixtureLoader struct {
	Path string
}

func (FixtureLoader) Load

type FlagKind

type FlagKind string

type FlagSpec

type FlagSpec struct {
	PropertyName string
	FlagName     string
	Alias        string
	Shorthand    string
	Kind         FlagKind
	Description  string
}

func BuildFlagSpecs

func BuildFlagSpecs(schema map[string]any, hints map[string]ir.CLIFlagHint) []FlagSpec

type StaticLoader

type StaticLoader struct {
	Catalog ir.Catalog
}

func (StaticLoader) Load

func (l StaticLoader) Load(_ context.Context) (ir.Catalog, error)

type StdinGuard

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

StdinGuard ensures stdin is consumed at most once per command invocation. Multiple flags using @- or implicit stdin fallback would race on the same reader; StdinGuard detects and rejects the second claim with a clear error.

func NewStdinGuard

func NewStdinGuard() *StdinGuard

NewStdinGuard creates a fresh guard for one command invocation.

func (*StdinGuard) Claim

func (g *StdinGuard) Claim(source string) error

Claim marks stdin as consumed by the named source (e.g. "--text @-"). Returns an error if stdin was already claimed.

func (*StdinGuard) Claimed

func (g *StdinGuard) Claimed() bool

Claimed reports whether stdin has been consumed.

Jump to

Keyboard shortcuts

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