cli

package
v0.7.1-0...-18ecb9a Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2026 License: MIT Imports: 37 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ExitSuccess         = 0
	ExitAssertionFailed = 1
	ExitRuntimeError    = 2
	ExitConfigError     = 3
)

Variables

View Source
var (
	QuietMode    bool
	OutputFormat string // "" (default pretty), "json"
)

Global flags accessible by all commands

View Source
var Version = "dev"

Version is set at build time via ldflags:

go build -ldflags "-X github.com/kest-labs/kest/internal/cli.Version=v1.0.0"

Functions

func Execute

func Execute()

func ExecuteRequest

func ExecuteRequest(opts RequestOptions) (summary.TestResult, error)

func FlowToMermaid

func FlowToMermaid(doc FlowDoc) string

FlowToMermaid renders a flowchart string for Mermaid.

func ParseCaptureExpr

func ParseCaptureExpr(expr string) (varName, query string, ok bool)

ParseCaptureExpr splits a capture expression like "token=data.auth.key" into (varName, query). Supports both "=" and ":" as separators.

func ParseFlowDocument

func ParseFlowDocument(content string) (FlowDoc, []KestBlock)

ParseFlowDocument parses Markdown content into FlowDoc and legacy Kest blocks.

func ResolveExecCapture

func ResolveExecCapture(output string, query string) string

ResolveExecCapture extracts a value from exec stdout based on the query.

Supported query formats:

  • $stdout → entire stdout
  • $line.N → Nth line (0-indexed)
  • <gjson path> → parse stdout as JSON, extract via gjson

func ShellCommand

func ShellCommand() (shell string, flag string)

ShellCommand returns the platform-appropriate shell and flag for exec steps.

Types

type AIResponse

type AIResponse struct {
	Summary    string          `json:"summary"`
	Request    json.RawMessage `json:"request_example"`
	Response   json.RawMessage `json:"response_example"`
	Permission string          `json:"permission"`
	Flow       string          `json:"flow"`
}

type APISpecSync

type APISpecSync struct {
	Method      string                 `json:"method"`
	Path        string                 `json:"path"`
	Title       string                 `json:"title"`
	Summary     string                 `json:"summary,omitempty"`
	Description string                 `json:"description,omitempty"`
	Version     string                 `json:"version"`
	RequestBody map[string]interface{} `json:"request_body,omitempty"`
	Parameters  []Parameter            `json:"parameters,omitempty"`
	Responses   map[string]Response    `json:"responses,omitempty"`
	Examples    []Example              `json:"examples,omitempty"`
}

APISpecSync represents an API spec for syncing

type Example

type Example struct {
	Name           string            `json:"name"`
	RequestHeaders map[string]string `json:"request_headers,omitempty"`
	RequestBody    string            `json:"request_body,omitempty"`
	ResponseStatus int               `json:"response_status"`
	ResponseBody   string            `json:"response_body,omitempty"`
	DurationMs     int64             `json:"duration_ms"`
}

type ExecOptions

type ExecOptions struct {
	Command  string
	Captures []string
}

type ExitError

type ExitError struct {
	Code int
	Err  error
}

ExitError wraps an error with a specific exit code.

func (*ExitError) Error

func (e *ExitError) Error() string

func (*ExitError) Unwrap

func (e *ExitError) Unwrap() error

type FlowBlock

type FlowBlock struct {
	Kind    string
	LineNum int
	Raw     string
}

func ParseFlowMarkdown

func ParseFlowMarkdown(content string) []FlowBlock

ParseFlowMarkdown extracts fenced code blocks and returns flow-related blocks. It supports both ``` and ~~~ fences and keeps the info string kind (first token).

type FlowDoc

type FlowDoc struct {
	Meta  FlowMeta
	Steps []FlowStep
	Edges []FlowEdge
}

type FlowEdge

type FlowEdge struct {
	From    string
	To      string
	On      string
	LineNum int
}

type FlowMeta

type FlowMeta struct {
	ID      string
	Name    string
	Version string
	Env     string
	Tags    []string
}

type FlowStep

type FlowStep struct {
	ID          string
	Name        string
	Type        string
	Retry       int
	RetryWait   int
	MaxDuration int
	OnFail      string
	LineNum     int
	Raw         string
	Request     RequestOptions
	Exec        ExecOptions
}

type KestBlock

type KestBlock struct {
	LineNum int
	Raw     string
	IsBlock bool // true if it's a multi-line block from Markdown
}

KestBlock represents a test block extracted from Markdown or a single line from .kest

func ParseMarkdown

func ParseMarkdown(content string) []KestBlock

ParseMarkdown extracts kest code blocks from markdown content

type Parameter

type Parameter struct {
	Name        string                 `json:"name"`
	In          string                 `json:"in"` // query, header, path
	Description string                 `json:"description,omitempty"`
	Required    bool                   `json:"required"`
	Schema      map[string]interface{} `json:"schema"`
	Example     interface{}            `json:"example,omitempty"`
}

type RequestOptions

type RequestOptions struct {
	Method       string
	URL          string
	Data         string
	Headers      []string
	Queries      []string
	Captures     []string
	Asserts      []string
	Verbose      bool
	DebugVars    bool
	Stream       bool
	NoRecord     bool
	MaxDuration  int  // Max response time in milliseconds (--max-time)
	Retry        int  // Number of retries (0 = no retry)
	RetryWait    int  // Delay between retries in milliseconds (--retry-delay)
	SilentOutput bool // Suppress PrintResponse box (used by flow runner)
}

func ParseBlock

func ParseBlock(raw string) (RequestOptions, error)

ParseBlock parses a multi-line kest block into RequestOptions

type Response

type Response struct {
	Description string                 `json:"description"`
	ContentType string                 `json:"content_type"`
	Schema      map[string]interface{} `json:"schema"`
}

type RunContext

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

RunContext holds all runtime state for a single kest run invocation. It replaces the previous global CLIVars map with a properly scoped, thread-safe variable store that supports the full resolution chain:

config env vars → runtime captured vars → CLI --var flags → exec captures
var ActiveRunCtx *RunContext

ActiveRunCtx is the current run context. It is set at the start of runScenario and cleared when the run completes. Ad-hoc commands (kest get/post) work fine when this is nil — they simply have no CLI vars to inject.

func NewRunContext

func NewRunContext(cliVars map[string]string) *RunContext

NewRunContext creates a RunContext seeded with CLI --var flags.

func (*RunContext) All

func (rc *RunContext) All() map[string]string

All returns a copy of all variables.

func (*RunContext) Get

func (rc *RunContext) Get(key string) (string, bool)

Get returns a variable value and whether it exists.

func (*RunContext) Set

func (rc *RunContext) Set(key, value string)

Set stores a variable (used by exec captures and request captures).

type SyncRequest

type SyncRequest struct {
	ProjectID int             `json:"project_id"`
	Specs     []APISpecSync   `json:"specs"`
	Source    string          `json:"source"`
	Metadata  json.RawMessage `json:"metadata,omitempty"`
}

type SyncResponse

type SyncResponse struct {
	Created int      `json:"created"`
	Updated int      `json:"updated"`
	Skipped int      `json:"skipped"`
	Errors  []string `json:"errors,omitempty"`
}

Jump to

Keyboard shortcuts

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