Documentation
¶
Index ¶
- Constants
- Variables
- func AbsFloat(x float64) float64
- func AbsInt(x int64) int64
- func AddInternalFuncs()
- func CalculateCorrectedIndex(rawIdx, length int64, clamp bool) int64
- func ErrIndexOutOfBounds(i *Interpreter, node *ts.Node, idx int64, length int64)
- func GetEmbeddedCommandSrc(name string) *string
- func GetEnumColor(value string, possibleSortedValues []string) (r, g, b int, err error)
- func GetInvocationLogPath() string
- func GetInvocationLogsDir() string
- func InputConfirm(title string, prompt string) (bool, error)
- func JsonToString(jsonVal interface{}) string
- func LoadPickResource(i *Interpreter, callNode *ts.Node, jsonPath string) (PickResource, *RadError)
- func LogInvocation(entry InvocationLogEntry)
- func MaybeRotate()
- func ParseDuration(s string) (time.Duration, error)
- func RadToJsonType(arg RadValue) interface{}
- func RegisterInvocationLogging()
- func ResetGlobals()
- func ResolveSliceStartEnd(i *Interpreter, sliceNode *ts.Node, length int64) (int64, int64)
- func RunRepl() error
- func SetScriptPath(path string)
- func ToPrintable(val interface{}) string
- func ToPrintableQuoteStr(val interface{}, quoteStrings bool) string
- func TransformRadArgs(args []RadArg, transformer func(RadArg) string) []string
- func TypeAsString(val interface{}) string
- type ArgRangeConstraint
- type BaseRadArg
- func (f *BaseRadArg) Configured() bool
- func (f *BaseRadArg) DefaultAsString() string
- func (f *BaseRadArg) Excludes(otherArg RadArg) bool
- func (f *BaseRadArg) GetArgUsage() string
- func (f *BaseRadArg) GetDescription() string
- func (f *BaseRadArg) GetExternalName() string
- func (f *BaseRadArg) GetIdentifier() string
- func (f *BaseRadArg) GetNode() *ts.Node
- func (f *BaseRadArg) GetShort() string
- func (f *BaseRadArg) HasNonZeroDefault() bool
- func (f *BaseRadArg) Hidden(hide bool)
- func (f *BaseRadArg) IsDefined() bool
- func (f *BaseRadArg) IsHidden() bool
- func (f *BaseRadArg) IsNullable() bool
- func (f *BaseRadArg) IsOptional() bool
- func (f *BaseRadArg) IsVariadic() bool
- func (f *BaseRadArg) SetBypassValidation(bypass bool)
- func (f *BaseRadArg) SetValue(_ string)
- type BoolListRadArg
- type BoolRadArg
- type BufferReader
- type BuiltInFunc
- type Capture
- type CheckableReader
- type Clock
- type CodeCtx
- type ColumnSort
- type ConstraintCtx
- type CtrlKind
- type DefaultReplSession
- type DeferBlock
- type Delimiter
- type EmbeddedCmd
- type Env
- func (e *Env) GetJsonFieldVar(name string) (*JsonFieldVar, bool)
- func (e *Env) GetVar(name string) (RadValue, bool)
- func (e *Env) GetVarElseBug(i *Interpreter, node *ts.Node, name string) RadValue
- func (e *Env) NewChildEnv() Env
- func (e *Env) PrintShellExports()
- func (e *Env) SetJsonFieldVar(jsonFieldVar *JsonFieldVar)
- func (e *Env) SetVar(name string, v RadValue)
- func (e *Env) SetVarUpdatingEnclosing(name string, v RadValue, updateEnclosing bool)
- type ErrorCtx
- type EvalResult
- type ExecutionResult
- type ExpectedOutput
- type FileReader
- type FixedClock
- type FloatListRadArg
- type FloatRadArg
- type FuncInvocation
- func (f FuncInvocation) GetArg(name string) RadValue
- func (f FuncInvocation) GetBool(name string) bool
- func (f FuncInvocation) GetFloat(name string) float64
- func (f FuncInvocation) GetFn(name string) RadFn
- func (f FuncInvocation) GetInt(name string) int64
- func (f FuncInvocation) GetIntAllowingBool(name string) int64
- func (f FuncInvocation) GetList(name string) *RadList
- func (f FuncInvocation) GetMap(name string) *RadMap
- func (f FuncInvocation) GetStr(name string) RadString
- func (f FuncInvocation) Return(vals ...interface{}) RadValue
- func (f FuncInvocation) ReturnErrf(code rl.Error, msg string, args ...interface{}) RadValue
- type GeneralSort
- type HttpRequest
- type InputReader
- type IntListRadArg
- type IntRadArg
- type Interpreter
- func (i *Interpreter) EvaluateStatement(input string) (RadValue, error)
- func (i *Interpreter) GetSrc() string
- func (i *Interpreter) GetSrcForNode(node *ts.Node) string
- func (i *Interpreter) InitArgs(args []RadArg)
- func (i *Interpreter) InitBuiltIns()
- func (i *Interpreter) NewRadPanic(node *ts.Node, err RadValue) *RadPanic
- func (i *Interpreter) RegisterWithExit()
- func (i *Interpreter) Run()
- func (i *Interpreter) WithTmpSrc(tmpSrc string, fn func())
- type InterpreterInput
- type InvocationLogEntry
- type InvocationLoggingConfig
- type InvocationType
- type JsonFieldVar
- type JsonPath
- type JsonPathSegment
- type JsonPathSegmentIdx
- type Lambda
- type MockResponse
- type MockResponseSlice
- type NullWriter
- type OpType
- type PickResource
- type PickResourceOpt
- type PickResourceOptionSerde
- type PickResourceSerde
- type PosArg
- type Printer
- type RadArg
- type RadArgTypeT
- type RadBlockType
- type RadConfig
- type RadError
- type RadExitHandler
- type RadFn
- type RadHome
- func (r *RadHome) GetStash() *string
- func (r *RadHome) GetStashForId(id string) string
- func (r *RadHome) GetStashSub(subPath string, node *ts.Node) (string, *RadError)
- func (r *RadHome) LoadState(i *Interpreter, node *ts.Node) (RadValue, bool, *RadError)
- func (r *RadHome) SaveState(i *Interpreter, node *ts.Node, value RadValue) *RadError
- func (r *RadHome) SetStashId(id string)
- type RadIo
- type RadList
- func (l *RadList) Append(value RadValue)
- func (l *RadList) AsActualStringList(i *Interpreter, node *ts.Node) []string
- func (l *RadList) AsStringList(quoteStrings bool) []string
- func (l *RadList) Contains(val RadValue) bool
- func (l *RadList) Equals(r *RadList) bool
- func (l *RadList) GetIdx(i *Interpreter, idxNode *ts.Node) RadValue
- func (l *RadList) IndexAt(i *Interpreter, node *ts.Node, idx int64) RadValue
- func (l *RadList) IsEmpty() bool
- func (l *RadList) Join(sep string, prefix string, suffix string) RadString
- func (l *RadList) JoinWith(other *RadList) RadValue
- func (l *RadList) Len() int64
- func (l *RadList) LenInt() int
- func (l *RadList) ModifyIdx(i *Interpreter, idxNode *ts.Node, value RadValue)
- func (l *RadList) RemoveIdx(i *Interpreter, node *ts.Node, idx int)
- func (l *RadList) Slice(i *Interpreter, sliceNode *ts.Node) *RadList
- func (l *RadList) SortAccordingToIndices(i *Interpreter, node *ts.Node, indices []int64)
- func (l *RadList) ToGoList() []interface{}
- func (l *RadList) ToString() string
- type RadMap
- func (m *RadMap) AsErrMsg(i *Interpreter, node *ts.Node) string
- func (m *RadMap) ContainsKey(key RadValue) bool
- func (m *RadMap) Delete(key RadValue)
- func (l *RadMap) Equals(right *RadMap) bool
- func (m *RadMap) Get(key RadValue) (RadValue, bool)
- func (m *RadMap) GetNode(i *Interpreter, idxNode *ts.Node) RadValue
- func (m *RadMap) Keys() []RadValue
- func (m *RadMap) Len() int64
- func (m *RadMap) Range(fn func(key, value RadValue) bool)
- func (m *RadMap) Set(key RadValue, value RadValue)
- func (m *RadMap) SetPrimitiveBool(key string, value bool)
- func (m *RadMap) SetPrimitiveFloat(key string, value float64)
- func (m *RadMap) SetPrimitiveInt(key string, value int)
- func (m *RadMap) SetPrimitiveInt64(key string, value int64)
- func (m *RadMap) SetPrimitiveList(key string, value *RadList)
- func (m *RadMap) SetPrimitiveMap(key string, value *RadMap)
- func (m *RadMap) SetPrimitiveStr(key string, value string)
- func (m *RadMap) ToGoMap() map[string]interface{}
- func (m *RadMap) ToString() string
- func (m *RadMap) Values() []RadValue
- type RadNull
- type RadPanic
- type RadRunner
- type RadString
- func (s *RadString) Compare(other RadString) int
- func (s RadString) Concat(other RadString) RadString
- func (s RadString) ConcatStr(other string) RadString
- func (s RadString) CopyAttrTo(otherStr string) RadString
- func (s *RadString) CopyWithAttr(attr RadTextAttr) RadString
- func (s *RadString) DeepCopy() RadString
- func (s RadString) Equals(other RadString) bool
- func (s *RadString) Hyperlink(link RadString) RadString
- func (s *RadString) Index(i *Interpreter, idxNode *ts.Node) RadString
- func (s *RadString) IndexAt(idx int64) RadString
- func (s RadString) Len() int64
- func (s RadString) Lower() RadString
- func (s RadString) Plain() string
- func (s RadString) Repeat(multiplier int64) RadString
- func (s *RadString) Reverse() RadString
- func (s *RadString) SetAttr(attr RadTextAttr)
- func (s RadString) SetRgb(red int, green int, blue int)
- func (s RadString) SetRgb64(red int64, green int64, blue int64)
- func (s *RadString) SetSegmentsHyperlink(link RadString)
- func (s RadString) String() string
- func (s *RadString) ToRuneList() *RadList
- func (s *RadString) Trim(chars string) RadString
- func (s *RadString) TrimPrefix(prefix string) RadString
- func (s *RadString) TrimSuffix(suffix string) RadString
- func (s RadString) Upper() RadString
- type RadTextAttr
- type RadTypeVisitor
- func (v *RadTypeVisitor) ForBool(handler func(RadValue, bool)) *RadTypeVisitor
- func (v *RadTypeVisitor) ForDefault(handler func(RadValue)) *RadTypeVisitor
- func (v *RadTypeVisitor) ForError(handler func(RadValue, *RadError)) *RadTypeVisitor
- func (v *RadTypeVisitor) ForFloat(handler func(RadValue, float64)) *RadTypeVisitor
- func (v *RadTypeVisitor) ForFn(handler func(RadValue, RadFn)) *RadTypeVisitor
- func (v *RadTypeVisitor) ForInt(handler func(RadValue, int64)) *RadTypeVisitor
- func (v *RadTypeVisitor) ForList(handler func(RadValue, *RadList)) *RadTypeVisitor
- func (v *RadTypeVisitor) ForMap(handler func(RadValue, *RadMap)) *RadTypeVisitor
- func (v *RadTypeVisitor) ForNull(handler func(RadValue, RadNull)) *RadTypeVisitor
- func (v *RadTypeVisitor) ForString(handler func(RadValue, RadString)) *RadTypeVisitor
- func (v *RadTypeVisitor) UnhandledTypeError(val RadValue)
- func (v *RadTypeVisitor) Visit(acceptor RadTypeVisitorAcceptor)
- type RadTypeVisitorAcceptor
- type RadValue
- func (v RadValue) Accept(visitor *RadTypeVisitor)
- func (left RadValue) Equals(right RadValue) bool
- func (v RadValue) Hash() string
- func (v RadValue) Index(i *Interpreter, idxNode *ts.Node) RadValue
- func (v RadValue) IsError() bool
- func (v RadValue) IsNull() bool
- func (v RadValue) ModifyIdx(i *Interpreter, idxNode *ts.Node, rightValue RadValue)
- func (v RadValue) RequireBool(i *Interpreter, node *ts.Node) bool
- func (v RadValue) RequireError(i *Interpreter, node *ts.Node) *RadError
- func (v RadValue) RequireFloatAllowingInt(i *Interpreter, node *ts.Node) float64
- func (v RadValue) RequireFn(i *Interpreter, node *ts.Node) RadFn
- func (v RadValue) RequireInt(i *Interpreter, node *ts.Node) int64
- func (v RadValue) RequireIntAllowingBool(i *Interpreter, node *ts.Node) int64
- func (v RadValue) RequireList(i *Interpreter, node *ts.Node) *RadList
- func (v RadValue) RequireMap(i *Interpreter, node *ts.Node) *RadMap
- func (v RadValue) RequireNotType(i *Interpreter, node *ts.Node, errPrefix string, disallowedTypes ...rl.RadType) RadValue
- func (v RadValue) RequireStr(i *Interpreter, node *ts.Node) RadString
- func (v RadValue) RequireType(i *Interpreter, node *ts.Node, errPrefix string, allowedTypes ...rl.RadType) RadValue
- func (v RadValue) ToCompatSubject(i *Interpreter) (out rl.TypingCompatVal)
- func (v RadValue) ToGoValue() (out interface{})
- func (v RadValue) TruthyFalsy() bool
- func (v RadValue) TryGetBool() (bool, bool)
- func (v RadValue) TryGetError() (*RadError, bool)
- func (v RadValue) TryGetFloatAllowingInt() (float64, bool)
- func (v RadValue) TryGetFn() (RadFn, bool)
- func (v RadValue) TryGetList() (*RadList, bool)
- func (v RadValue) TryGetMap() (*RadMap, bool)
- func (v RadValue) TryGetStr() (RadString, bool)
- func (v RadValue) Type() rl.RadType
- type ReadlineInputReader
- type RealClock
- type RegistrationMode
- type ReplSession
- type RequestDef
- type Requester
- type ResponseDef
- type RunnerInput
- type ScriptArg
- type ScriptCommand
- type ScriptData
- type ShellExecutor
- type ShellInvocation
- type SingleLineInputReader
- type SortDir
- type StringListRadArg
- type StringRadArg
- type TblWriter
- type Trie
- type TrieNode
Constants ¶
const ( EmbCmdNew = "new" EmbCmdDocs = "docs" EmbCmdHome = "home" EmbCmdGenId = "gen-id" EmbCmdStash = "stash" EmbCmdCheck = "check" )
const ( UNREACHABLE = "Bug! This should be unreachable" NOT_IMPLEMENTED = "not implemented" NO_NUM_RETURN_VALUES_CONSTRAINT = -1 USAGE_ALIGNMENT_CHAR = "\x00" PADDING_CHAR = "\x00" )
const ( WILDCARD = "*" MACRO_STASH_ID = "stash_id" MACRO_ENABLE_GLOBAL_OPTIONS = "enable_global_options" MACRO_ENABLE_ARGS_BLOCK = "enable_args_block" )
const ( COLOR_AUTO = "auto" COLOR_ALWAYS = "always" COLOR_NEVER = "never" FLAG_HELP = "help" FLAG_H = "h" FLAG_DEBUG = "debug" FLAG_D = "d" FLAG_RAD_DEBUG = "rad-debug" FLAG_COLOR = "color" FLAG_QUIET = "quiet" FLAG_Q = "q" FLAG_SHELL = "shell" FLAG_VERSION = "version" FLAG_V = "v" FLAG_CONFIRM_SHELL = "confirm-shell" FLAG_SRC = "src" FLAG_SRC_TREE = "src-tree" FLAG_RAD_ARGS_DUMP = "rad-args-dump" FLAG_MOCK_RESPONSE = "mock-response" FLAG_REPL = "repl" FLAG_R = "r" )
const ( FUNC_PRINT = "print" FUNC_PRINT_ERR = "print_err" FUNC_PPRINT = "pprint" FUNC_DEBUG = "debug" FUNC_EXIT = "exit" FUNC_SLEEP = "sleep" FUNC_SEED_RANDOM = "seed_random" FUNC_RAND = "rand" FUNC_RAND_INT = "rand_int" FUNC_REPLACE = "replace" FUNC_LEN = "len" FUNC_SORT = "sort" FUNC_NOW = "now" FUNC_PARSE_EPOCH = "parse_epoch" FUNC_TYPE_OF = "type_of" FUNC_JOIN = "join" FUNC_UPPER = "upper" FUNC_LOWER = "lower" FUNC_STARTS_WITH = "starts_with" FUNC_ENDS_WITH = "ends_with" FUNC_PICK = "pick" FUNC_PICK_KV = "pick_kv" FUNC_PICK_FROM_RESOURCE = "pick_from_resource" FUNC_MULTIPICK = "multipick" FUNC_KEYS = "keys" FUNC_VALUES = "values" FUNC_TRUNCATE = "truncate" FUNC_SPLIT = "split" FUNC_RANGE = "range" FUNC_UNIQUE = "unique" FUNC_CONFIRM = "confirm" FUNC_INPUT = "input" FUNC_PARSE_JSON = "parse_json" FUNC_PARSE_INT = "parse_int" FUNC_PARSE_FLOAT = "parse_float" FUNC_HTTP_GET = "http_get" FUNC_HTTP_POST = "http_post" FUNC_HTTP_PUT = "http_put" FUNC_HTTP_PATCH = "http_patch" FUNC_HTTP_DELETE = "http_delete" FUNC_HTTP_HEAD = "http_head" FUNC_HTTP_OPTIONS = "http_options" FUNC_HTTP_TRACE = "http_trace" FUNC_HTTP_CONNECT = "http_connect" FUNC_ABS = "abs" FUNC_POW = "pow" FUNC_ERROR = "error" FUNC_GET_PATH = "get_path" FUNC_FIND_PATHS = "find_paths" FUNC_DELETE_PATH = "delete_path" FUNC_COUNT = "count" FUNC_ZIP = "zip" FUNC_STR = "str" FUNC_INT = "int" FUNC_FLOAT = "float" FUNC_SUM = "sum" FUNC_TRIM = "trim" FUNC_TRIM_PREFIX = "trim_prefix" FUNC_TRIM_SUFFIX = "trim_suffix" FUNC_READ_FILE = "read_file" FUNC_WRITE_FILE = "write_file" FUNC_READ_STDIN = "read_stdin" FUNC_HAS_STDIN = "has_stdin" FUNC_ROUND = "round" FUNC_CEIL = "ceil" FUNC_FLOOR = "floor" FUNC_MIN = "min" FUNC_MAX = "max" FUNC_MATCHES = "matches" FUNC_CLAMP = "clamp" FUNC_REVERSE = "reverse" FUNC_IS_DEFINED = "is_defined" // todo might be poorly named. should focus on vars. Or maybe just embrace works for anything, name it 'exists'? FUNC_HYPERLINK = "hyperlink" FUNC_UUID_V4 = "uuid_v4" FUNC_UUID_V7 = "uuid_v7" FUNC_GEN_FID = "gen_fid" FUNC_GET_DEFAULT = "get_default" FUNC_GET_RAD_HOME = "get_rad_home" FUNC_GET_STASH_DIR = "get_stash_dir" // todo 'path' vs. 'dir' inconsistent naming FUNC_LOAD_STATE = "load_state" FUNC_SAVE_STATE = "save_state" FUNC_LOAD_STASH_FILE = "load_stash_file" FUNC_WRITE_STASH_FILE = "write_stash_file" FUNC_GET_ENV = "get_env" FUNC_HASH = "hash" FUNC_ENCODE_BASE64 = "encode_base64" FUNC_DECODE_BASE64 = "decode_base64" FUNC_ENCODE_BASE16 = "encode_base16" FUNC_DECODE_BASE16 = "decode_base16" FUNC_MAP = "map" FUNC_FILTER = "filter" FUNC_FLAT_MAP = "flat_map" FUNC_LOAD = "load" FUNC_COLOR_RGB = "color_rgb" FUNC_COLORIZE = "colorize" FUNC_GET_ARGS = "get_args" INTERNAL_FUNC_GET_STASH_ID = "_rad_get_stash_id" INTERNAL_FUNC_DELETE_STASH = "_rad_delete_stash" INTERNAL_FUNC_RUN_CHECK = "_rad_run_check" INTERNAL_FUNC_CHECK_FROM_LOGS = "_rad_check_from_logs" )
const ENV_RAD_HOME = "RAD_HOME"
const (
Version = "v0.6.27"
)
Variables ¶
var ( MODES = []string{COLOR_AUTO, COLOR_ALWAYS, COLOR_NEVER} NO_CONSTRAINTS []string FlagHelp BoolRadArg FlagDebug BoolRadArg FlagRadDebug BoolRadArg FlagColor StringRadArg FlagQuiet BoolRadArg FlagShell BoolRadArg FlagVersion BoolRadArg FlagConfirmShellCommands BoolRadArg FlagSrc BoolRadArg FlagSrcTree BoolRadArg FlagRadArgsDump BoolRadArg FlagMockResponse StringRadArg FlagRepl BoolRadArg )
var ( RRootCmd *ra.Cmd RConfig *RadConfig RP Printer RIo RadIo RExit *RadExitHandler RReq *Requester RClock Clock RSleep func(duration time.Duration) RShell ShellExecutor RNG *rand.Rand HasScript bool ScriptPath string ScriptDir string ScriptName string IsTest bool AlreadyExportedShellVars bool StartEpochMillis int64 )
var ATTR_STRINGS = make([]string, 0)
var Cmds []EmbeddedCmd
var CmdsByName map[string]EmbeddedCmd
var EMPTY_STR = NewRadString("")
var FuncColorize = BuiltInFunc{ Name: FUNC_COLORIZE, Execute: func(f FuncInvocation) RadValue { strVal := ToPrintableQuoteStr(f.GetArg("_val"), false) enum := lo.Uniq(f.GetList("_enum").AsStringList(false)) skipIfSingle := f.GetBool("skip_if_single") if len(enum) == 0 { return f.ReturnErrf(rl.ErrEmptyList, "Possible values list cannot be empty, but was.") } if skipIfSingle && len(enum) == 1 { s := NewRadString(strVal) return f.Return(s) } sort.Strings(enum) if !lo.Contains(enum, strVal) { return f.ReturnErrf(rl.ErrColorizeValNotInEnum, "Value '%s' not found in the provided list of possible values: %s", strVal, enum) } r, g, b, err := GetEnumColor(strVal, enum) if err != nil { return f.ReturnErrf(rl.ErrEmptyList, "Failed to get color for value '%s': %s", strVal, err.Error()) } s := NewRadString(strVal) s.SetRgb(r, g, b) return f.Return(s) }, }
var FuncDebug = BuiltInFunc{ Name: FUNC_DEBUG, Execute: func(f FuncInvocation) RadValue { RP.ScriptDebug(resolvePrintStr(f)) return VOID_SENTINEL }, }
var FuncExit = BuiltInFunc{ Name: FUNC_EXIT, Execute: func(f FuncInvocation) RadValue { err := f.GetIntAllowingBool("_code") exit(f.i, err) return VOID_SENTINEL }, }
var FuncInternalCheckFromLogs = BuiltInFunc{ Name: INTERNAL_FUNC_CHECK_FROM_LOGS, Execute: func(f FuncInvocation) RadValue { raw := strings.TrimSpace(f.GetStr("_duration").Plain()) d, err := ParseDuration(raw) if err != nil { return f.ReturnErrf(rl.ErrInvalidCheckDuration, "Invalid duration: %s", err.Error()) } if d < 0 { return f.ReturnErrf(rl.ErrInvalidCheckDuration, "Duration cannot be negative: %s", raw) } durationMillis := d.Milliseconds() verbose := f.GetBool("_verbose") scripts := parseInvocationLogs(f.i, f.callNode, durationMillis) sortScriptsByLastOccurrence(scripts) durationDesc := raw if durationMillis == 0 { durationDesc = "all time" } RP.Printf("Found %d scripts in invocation logs (checking within %s)...\n\n", len(scripts), durationDesc) chk, err := check.NewChecker() if err != nil { chk = nil RP.RadStderrf("Warning! Failed to init checker once, will init per file: %v\n", err) } totalChecked, passed, failed, skipped := 0, 0, 0, 0 for _, script := range scripts { if !com.FileExists(script.Path) { skipped++ if verbose { dimmed := color.New(color.Faint) RP.Printf(" %s\n", dimmed.Sprintf("- %s (file not found)", script.Path)) } continue } ok := checkScriptWith(script.Path, chk) totalChecked++ if ok { green := color.New(color.FgGreen) RP.Printf(" %s %s\n", green.Sprint("✓"), script.Path) passed++ } else { red := color.New(color.FgRed) RP.Printf(" %s %s\n", red.Sprint("✗"), script.Path) failed++ } } RP.Printf("\n────────────────────────────────────────\n") bold := color.New(color.Bold) green := color.New(color.FgGreen) red := color.New(color.FgRed) faint := color.New(color.Faint) summary := fmt.Sprintf("Checked %d scripts: %s passed, %s failed", totalChecked, green.Sprintf("%d", passed), red.Sprintf("%d", failed)) if skipped > 0 { summary += fmt.Sprintf(" (%s skipped)", faint.Sprintf("%d", skipped)) } RP.Printf("%s.\n", bold.Sprint(summary)) if failed > 0 { RExit.Exit(1) } else { RExit.Exit(0) } return VOID_SENTINEL }, }
FuncInternalCheckFromLogs implements _rad_check_from_logs, which checks rad scripts from invocation logs for syntax/semantic errors. This is an internal function used by the rad CLI for bulk checking recently-used scripts.
var FuncMatches = BuiltInFunc{ Name: FUNC_MATCHES, Execute: func(f FuncInvocation) RadValue { input := f.GetStr("_str").Plain() pattern := f.GetStr("_pattern").Plain() partial := f.GetBool("partial") re, err := regexp.Compile(pattern) if err != nil { return f.ReturnErrf(rl.ErrInvalidRegex, "Error compiling regex pattern: %s", err) } var matches bool if partial { matches = re.FindString(input) != "" } else { anchoredPattern := "^(?:" + pattern + ")$" anchoredRe, err := regexp.Compile(anchoredPattern) if err != nil { return f.ReturnErrf(rl.ErrInvalidRegex, "Error compiling regex pattern: %s", err) } matches = anchoredRe.MatchString(input) } return f.Return(matches) }, }
var FuncMultipick = BuiltInFunc{ Name: FUNC_MULTIPICK, Execute: func(f FuncInvocation) RadValue { options := f.GetList("_options").AsStringList(false) if len(options) == 0 { return f.Return(NewErrorStrf("Cannot multipick from empty options list")) } minArg := f.GetArg("min") maxArg := f.GetArg("max") promptArg := f.GetArg("prompt") min := int64(0) if !minArg.IsNull() { min = minArg.RequireInt(f.i, f.callNode) } if min < 0 { return f.Return(NewErrorStrf("min must be non-negative, got %d", min)) } // Get max value (optional) var max *int64 if !maxArg.IsNull() { maxVal := maxArg.RequireInt(f.i, f.callNode) max = &maxVal if maxVal <= 0 { return f.Return(NewErrorStrf("max must be positive, got %d", maxVal)) } if min > maxVal { return f.Return(NewErrorStrf("min (%d) cannot be greater than max (%d)", min, maxVal)) } } if min > int64(len(options)) { if min == 1 { return f.Return(NewErrorStrf("min is 1 but there are no options available")) } else { return f.Return(NewErrorStrf("min is %d but only %d options available", min, len(options))) } } // Generate smart default prompt if not provided var prompt string if promptArg.IsNull() { prompt = generateMultipickPrompt(min, max) } else { prompt = f.GetStr("prompt").Plain() if prompt == "" { prompt = " " } } opts := make([]huh.Option[string], len(options)) for i, opt := range options { opts[i] = huh.NewOption(opt, opt) } multiSelect := huh.NewMultiSelect[string](). Title(prompt). Options(opts...). Validate(func(selected []string) error { count := int64(len(selected)) if max != nil && min == *max { if count != min { if min == 1 { return fmt.Errorf("Must select exactly 1 option, but selected %d", count) } else { return fmt.Errorf("Must select exactly %d options, but selected %d", min, count) } } return nil } if count < min { if min == 1 { return fmt.Errorf("Must select at least 1 option, but only selected %d", count) } else { return fmt.Errorf("Must select at least %d options, but only selected %d", min, count) } } if max != nil && count > *max { if *max == 1 { return fmt.Errorf("Must select at most 1 option, but selected %d", count) } else { return fmt.Errorf("Must select at most %d options, but selected %d", *max, count) } } return nil }) if max != nil { multiSelect = multiSelect.Limit(int(*max)) } // Execute the selection var selected []string multiSelect = multiSelect.Value(&selected) if err := multiSelect.Run(); err != nil { return f.Return(NewErrorStrf("Error running multipick: %v", err)) } result := NewRadList() for _, item := range selected { result.Append(newRadValueStr(item)) } return f.Return(result) }, }
var FuncPPrint = BuiltInFunc{ Name: FUNC_PPRINT, Execute: func(f FuncInvocation) RadValue { item := f.GetArg("_item") jsonStruct := RadToJsonType(item) output := prettify(f.i, f.callNode, jsonStruct) RP.Print(output) return VOID_SENTINEL }, }
var FuncPick = BuiltInFunc{ Name: FUNC_PICK, Execute: func(f FuncInvocation) RadValue { options := f.GetList("_options").AsStringList(false) filterArg := f.GetArg("_filter") filters := make([]string, 0) if !filterArg.IsNull() { switch coerced := filterArg.Val.(type) { case RadString: filters = append(filters, coerced.Plain()) case *RadList: for _, item := range coerced.Values { filters = append(filters, item.RequireStr(f.i, f.callNode).Plain()) } default: bugIncorrectTypes(FUNC_PICK) } } keyGroups := lo.Map(options, func(key string, _ int) []string { return []string{key} }) prioExact := f.GetBool(namedArgPreferExact) str, err := pickKv(f, keyGroups, keyGroups, filters, prioExact) if err != nil { return f.Return(err) } return f.Return(str[0]) }, }
var FuncPickFromResource = BuiltInFunc{ Name: FUNC_PICK_FROM_RESOURCE, Execute: func(f FuncInvocation) RadValue { path := f.GetStr("path").Plain() filter := f.GetArg("_filter") resource, err := LoadPickResource(f.i, f.callNode, path) if err != nil { return f.Return(err) } var keyGroups [][]string var valueGroups [][]RadValue for _, opt := range resource.Opts { keyGroups = append(keyGroups, opt.Keys) valueGroups = append(valueGroups, opt.Values) } filters := make([]string, 0) if !filter.IsNull() { switch coerced := filter.Val.(type) { case RadString: filters = append(filters, coerced.Plain()) case *RadList: for _, item := range coerced.Values { filters = append(filters, item.RequireStr(f.i, f.callNode).Plain()) } default: bugIncorrectTypes(FUNC_PICK_KV) } } prioExact := f.GetBool(namedArgPreferExact) out, err := pickKv(f, keyGroups, valueGroups, filters, prioExact) if err != nil { return f.Return(err) } if len(out) == 1 { return newRadValues(f.i, f.callNode, out[0]) } else { return newRadValues(f.i, f.callNode, out) } }, }
var FuncPickKv = BuiltInFunc{ Name: FUNC_PICK_KV, Execute: func(f FuncInvocation) RadValue { keys := f.GetList("keys").AsStringList(false) values := f.GetList("values").Values filter := f.GetArg("_filter") filters := make([]string, 0) if !filter.IsNull() { switch coerced := filter.Val.(type) { case RadString: filters = append(filters, coerced.Plain()) case *RadList: for _, item := range coerced.Values { filters = append(filters, item.RequireStr(f.i, f.callNode).Plain()) } default: bugIncorrectTypes(FUNC_PICK_KV) } } keyGroups := lo.Map(keys, func(key string, _ int) []string { return []string{key} }) valueGroups := lo.Map(values, func(value RadValue, _ int) []RadValue { return []RadValue{value} }) prioExact := f.GetBool(namedArgPreferExact) out, err := pickKv(f, keyGroups, valueGroups, filters, prioExact) if err != nil { return f.Return(err) } return f.Return(out[0]) }, }
var FuncPrint = BuiltInFunc{ Name: FUNC_PRINT, Execute: func(f FuncInvocation) RadValue { RP.Print(resolvePrintStr(f)) return VOID_SENTINEL }, }
var FuncPrintErr = BuiltInFunc{ Name: FUNC_PRINT_ERR, Execute: func(f FuncInvocation) RadValue { RP.ScriptStderrf(resolvePrintStr(f)) return VOID_SENTINEL }, }
var FuncRand = BuiltInFunc{ Name: FUNC_RAND, Execute: func(f FuncInvocation) RadValue { return f.Return(RNG.Float64()) }, }
var FuncRandInt = BuiltInFunc{ Name: FUNC_RAND_INT, Execute: func(f FuncInvocation) RadValue { arg1 := f.GetInt("_arg1") arg2 := f.GetArg("_arg2") var min, max int64 if arg2.IsNull() { min = 0 max = arg1 } else { min = arg1 max = arg2.RequireInt(f.i, f.callNode) } if min >= max { return f.ReturnErrf(rl.ErrArgsContradict, "min (%d) must be less than max (%d).", min, max) } n := max - min return newRadValues(f.i, f.callNode, min+RNG.Int63n(n)) }, }
var FuncRange = BuiltInFunc{ Name: FUNC_RANGE, Execute: func(f FuncInvocation) RadValue { useFloats := false arg1 := f.GetArg("_arg1") arg2 := f.GetArg("_arg2") step := f.GetArg("_step") for _, arg := range []RadValue{arg1, arg2, step} { switch arg.Type() { case rl.RadFloatT: useFloats = true case rl.RadIntT, rl.RadNullT: default: bugIncorrectTypes(FUNC_RANGE) } } if useFloats { return runFloatRange(f, arg1, arg2, step) } else { return runIntRange(f, arg1, arg2, step) } }, }
var FuncReplace = BuiltInFunc{ Name: FUNC_REPLACE, Execute: func(f FuncInvocation) RadValue { original := f.GetStr("_original").Plain() find := f.GetStr("_find").Plain() replace := f.GetStr("_replace").Plain() re, err := regexp.Compile(find) if err != nil { return f.ReturnErrf(rl.ErrInvalidRegex, "Error compiling regex pattern: %s", err) } replacementFunc := func(match string) string { submatches := re.FindStringSubmatch(match) if len(submatches) == 0 { return match } result := replace for i, submatch := range submatches { placeholder := fmt.Sprintf("$%d", i) result = strings.ReplaceAll(result, placeholder, submatch) } return result } newString := re.ReplaceAllStringFunc(original, replacementFunc) return f.Return(newString) }, }
Allows capture group replacing, for example replace("Name: abc", "a(b)c", "$1o$1") will return "Name: bobby"
var FuncSeedRandom = BuiltInFunc{ Name: FUNC_SEED_RANDOM, Execute: func(f FuncInvocation) RadValue { RNG = rand.New(rand.NewSource(f.GetInt("_seed"))) return VOID_SENTINEL }, }
var FuncSleep = BuiltInFunc{ Name: FUNC_SLEEP, Execute: func(f FuncInvocation) RadValue { duration := f.GetArg("_duration") switch coerced := duration.Val.(type) { case int64: err := sleep(time.Duration(coerced)*time.Second, f.namedArgs) if err != nil { return f.Return(err) } return VOID_SENTINEL case float64: err := sleep(time.Duration(coerced*1000)*time.Millisecond, f.namedArgs) if err != nil { return f.Return(err) } return VOID_SENTINEL case RadString: durStr := strings.Replace(coerced.Plain(), " ", "", -1) floatVal, err := rts.ParseFloat(durStr) if err == nil { err := sleep(time.Duration(floatVal*1000)*time.Millisecond, f.namedArgs) if err != nil { return f.Return(err) } return VOID_SENTINEL } dur, err := time.ParseDuration(durStr) if err == nil { err := sleep(dur, f.namedArgs) if err != nil { return f.Return(err) } return VOID_SENTINEL } return f.ReturnErrf(rl.ErrSleepStr, "Invalid string argument: %q", coerced.Plain()) default: bugIncorrectTypes(FUNC_SLEEP) panic(UNREACHABLE) } }, }
var FuncSplit = BuiltInFunc{ Name: FUNC_SPLIT, Execute: func(f FuncInvocation) RadValue { toSplit := f.GetStr("_val").Plain() splitter := f.GetStr("_sep").Plain() return f.Return(regexSplit(f.i, f.callNode, toSplit, splitter)) }, }
var FunctionsByName map[string]BuiltInFunc
var (
NO_NAMED_ARGS_INPUT = map[string]namedArg{}
)
var RAD_NULL = RadNull{}
var RAD_NULL_VAL = newRadValue(nil, nil, RAD_NULL)
var VOID_SENTINEL = RadValue{Val: 0x0}
used to internally delete things e.g. vars from env, but also empty returns. too much? subtle bugs?
var VoidBreak = NewEvalResult(VOID_SENTINEL, CtrlBreak)
var VoidContinue = NewEvalResult(VOID_SENTINEL, CtrlContinue)
var VoidNormal = NewEvalResult(VOID_SENTINEL, CtrlNormal)
Functions ¶
func AddInternalFuncs ¶
func AddInternalFuncs()
func CalculateCorrectedIndex ¶
'corrects' negative indices into their positive equivalents
func ErrIndexOutOfBounds ¶
func ErrIndexOutOfBounds(i *Interpreter, node *ts.Node, idx int64, length int64)
func GetEmbeddedCommandSrc ¶
func GetEnumColor ¶
GetEnumColor generates a visually distinct and appealing RGB color for a given value from a list. It returns R, G, B values (0-255) and an error if the value is not found.
func GetInvocationLogPath ¶ added in v0.6.11
func GetInvocationLogPath() string
GetInvocationLogPath returns the path to the current invocation log file
func GetInvocationLogsDir ¶ added in v0.6.11
func GetInvocationLogsDir() string
GetInvocationLogsDir returns the directory containing invocation logs
func InputConfirm ¶
todo allow controlling 'yes' response?
func JsonToString ¶
func JsonToString(jsonVal interface{}) string
func LoadPickResource ¶
func LoadPickResource(i *Interpreter, callNode *ts.Node, jsonPath string) (PickResource, *RadError)
func LogInvocation ¶ added in v0.6.11
func LogInvocation(entry InvocationLogEntry)
LogInvocation appends an invocation log entry to the JSONL log file Creates directory and file if they don't exist
func MaybeRotate ¶ added in v0.6.11
func MaybeRotate()
MaybeRotate checks if the current log file exceeds the size threshold and rotates it if necessary. Non-fatal: warns on errors but doesn't crash.
func ParseDuration ¶ added in v0.6.11
ParseDuration parses a human-readable duration string into time.Duration Supported formats:
- Simple: "30d", "2w", "24h", "1y"
- Combinations: "2w3d", "1y2w", "3d12h30m"
- Special: "all" returns 0 (no time filtering)
Units:
- y: years (365 days, ignores leap years)
- w: weeks (7 days)
- d: days (24 hours)
- h: hours
- m: minutes
- s: seconds
func RadToJsonType ¶
func RadToJsonType(arg RadValue) interface{}
converts a Rad data structure to a JSON-schema-adhering structure.
func RegisterInvocationLogging ¶ added in v0.6.11
func RegisterInvocationLogging()
func ResolveSliceStartEnd ¶
func SetScriptPath ¶
func SetScriptPath(path string)
func ToPrintable ¶
func ToPrintable(val interface{}) string
func ToPrintableQuoteStr ¶
func TransformRadArgs ¶
func TypeAsString ¶
func TypeAsString(val interface{}) string
Types ¶
type ArgRangeConstraint ¶
type BaseRadArg ¶
type BaseRadArg struct {
ExternalName string // User-facing arg they'll set in CLI
Identifier string // Identifier in script. If non-script arg, then equal to ExternalName
Short string
ArgUsage string
Description string
// contains filtered or unexported fields
}
func (*BaseRadArg) Configured ¶
func (f *BaseRadArg) Configured() bool
func (*BaseRadArg) DefaultAsString ¶
func (f *BaseRadArg) DefaultAsString() string
func (*BaseRadArg) Excludes ¶
func (f *BaseRadArg) Excludes(otherArg RadArg) bool
func (*BaseRadArg) GetArgUsage ¶
func (f *BaseRadArg) GetArgUsage() string
func (*BaseRadArg) GetDescription ¶
func (f *BaseRadArg) GetDescription() string
func (*BaseRadArg) GetExternalName ¶
func (f *BaseRadArg) GetExternalName() string
func (*BaseRadArg) GetIdentifier ¶
func (f *BaseRadArg) GetIdentifier() string
func (*BaseRadArg) GetNode ¶
func (f *BaseRadArg) GetNode() *ts.Node
func (*BaseRadArg) GetShort ¶
func (f *BaseRadArg) GetShort() string
func (*BaseRadArg) HasNonZeroDefault ¶
func (f *BaseRadArg) HasNonZeroDefault() bool
func (*BaseRadArg) Hidden ¶
func (f *BaseRadArg) Hidden(hide bool)
func (*BaseRadArg) IsDefined ¶
func (f *BaseRadArg) IsDefined() bool
func (*BaseRadArg) IsHidden ¶
func (f *BaseRadArg) IsHidden() bool
func (*BaseRadArg) IsNullable ¶
func (f *BaseRadArg) IsNullable() bool
func (*BaseRadArg) IsOptional ¶
func (f *BaseRadArg) IsOptional() bool
func (*BaseRadArg) IsVariadic ¶ added in v0.6.0
func (f *BaseRadArg) IsVariadic() bool
func (*BaseRadArg) SetBypassValidation ¶ added in v0.5.59
func (f *BaseRadArg) SetBypassValidation(bypass bool)
func (*BaseRadArg) SetValue ¶
func (f *BaseRadArg) SetValue(_ string)
type BoolListRadArg ¶
type BoolListRadArg struct {
BaseRadArg
Value []bool
Default []bool
}
func NewBoolListRadArg ¶
func NewBoolListRadArg(name, short, argUsage, description string, hasDefault bool, defaultValue []bool, requires, excludes []string, ) BoolListRadArg
func (*BoolListRadArg) GetType ¶
func (f *BoolListRadArg) GetType() RadArgTypeT
func (*BoolListRadArg) Register ¶
func (f *BoolListRadArg) Register(cmd *ra.Cmd, mode RegistrationMode)
func (*BoolListRadArg) SetValue ¶
func (f *BoolListRadArg) SetValue(arg string)
type BoolRadArg ¶
type BoolRadArg struct {
BaseRadArg
Value bool
Default bool
}
func NewBoolRadArg ¶
func NewBoolRadArg(name, short, description string, hasDefault bool, defaultValue bool, requires, excludes []string, ) BoolRadArg
func (*BoolRadArg) GetType ¶
func (f *BoolRadArg) GetType() RadArgTypeT
func (*BoolRadArg) Register ¶
func (f *BoolRadArg) Register(cmd *ra.Cmd, mode RegistrationMode)
func (*BoolRadArg) SetValue ¶
func (f *BoolRadArg) SetValue(arg string)
type BufferReader ¶
type BufferReader struct {
// contains filtered or unexported fields
}
func (*BufferReader) HasContent ¶
func (br *BufferReader) HasContent() bool
func (*BufferReader) SetPiped ¶ added in v0.6.10
func (br *BufferReader) SetPiped(piped bool)
func (*BufferReader) Unwrap ¶
func (br *BufferReader) Unwrap() io.Reader
type BuiltInFunc ¶
type BuiltInFunc struct {
Name string
Signature *rts.FnSignature
Execute func(FuncInvocation) RadValue
}
todo add 'usage' to each function? self-documenting errors when incorrectly using
type CheckableReader ¶
type CheckableReader interface {
Read(p []byte) (n int, err error)
HasContent() bool
Unwrap() io.Reader
}
func NewBufferReader ¶
func NewBufferReader(buffer *bytes.Buffer) CheckableReader
func NewFileReader ¶
func NewFileReader(file *os.File) CheckableReader
type ColumnSort ¶
type ConstraintCtx ¶
func NewConstraintCtx ¶
func NewConstraintCtx(scriptArgs []RadArg) ConstraintCtx
type DefaultReplSession ¶ added in v0.5.59
type DefaultReplSession struct {
// contains filtered or unexported fields
}
DefaultReplSession implements the ReplSession interface
func (*DefaultReplSession) ExecuteStatement ¶ added in v0.5.59
func (s *DefaultReplSession) ExecuteStatement(input string) (*ExecutionResult, error)
ExecuteStatement executes a single statement and returns the result
func (*DefaultReplSession) GetEnvironment ¶ added in v0.5.59
func (s *DefaultReplSession) GetEnvironment() *Env
GetEnvironment returns the current interpreter environment
func (*DefaultReplSession) Run ¶ added in v0.5.59
func (s *DefaultReplSession) Run() error
Run starts the main REPL loop
func (*DefaultReplSession) Shutdown ¶ added in v0.5.59
func (s *DefaultReplSession) Shutdown() error
Shutdown performs cleanup when REPL session ends
type DeferBlock ¶
func NewDeferBlock ¶
func NewDeferBlock(i *Interpreter, deferKeywordNode *ts.Node, stmtNodes []ts.Node) *DeferBlock
type EmbeddedCmd ¶
type Env ¶
type Env struct {
Enclosing *Env
Vars map[string]RadValue
JsonFieldVars map[string]*JsonFieldVar // not pointer?
// contains filtered or unexported fields
}
func NewEnv ¶
func NewEnv(i *Interpreter) *Env
func (*Env) GetJsonFieldVar ¶
func (e *Env) GetJsonFieldVar(name string) (*JsonFieldVar, bool)
func (*Env) GetVarElseBug ¶
func (*Env) NewChildEnv ¶
func (*Env) PrintShellExports ¶
func (e *Env) PrintShellExports()
func (*Env) SetJsonFieldVar ¶
func (e *Env) SetJsonFieldVar(jsonFieldVar *JsonFieldVar)
type ErrorCtx ¶
type ErrorCtx struct {
CodeCtx
OneLiner string
Details string
Suggestion *string // Optional suggestion for fixing the error (rendered as "Try: ...")
}
TODO require RadError code? TODO perhaps include a map[node]string for multiple explanations for different parts of the code?
type EvalResult ¶
func NewEvalResult ¶
func NewEvalResult(val RadValue, ctrl CtrlKind) EvalResult
func NormalVal ¶
func NormalVal(val RadValue) EvalResult
func ReturnVal ¶
func ReturnVal(val RadValue) EvalResult
func YieldVal ¶
func YieldVal(val RadValue) EvalResult
type ExecutionResult ¶ added in v0.5.59
ExecutionResult represents the result of executing a statement
func NewExecutionResult ¶ added in v0.5.59
func NewExecutionResult(value RadValue, shouldPrint bool, err *RadError) *ExecutionResult
NewExecutionResult creates a new execution result
type ExpectedOutput ¶
type ExpectedOutput int
const ( Zero ExpectedOutput = iota One NoConstraint )
func (ExpectedOutput) Acceptable ¶
func (e ExpectedOutput) Acceptable(actual int) bool
func (ExpectedOutput) String ¶
func (e ExpectedOutput) String() string
type FileReader ¶
type FileReader struct {
// contains filtered or unexported fields
}
func (*FileReader) HasContent ¶
func (fr *FileReader) HasContent() bool
func (*FileReader) Unwrap ¶
func (fr *FileReader) Unwrap() io.Reader
type FixedClock ¶
func (*FixedClock) Local ¶ added in v0.6.7
func (f *FixedClock) Local() *time.Location
func (*FixedClock) Now ¶
func (f *FixedClock) Now() time.Time
type FloatListRadArg ¶
type FloatListRadArg struct {
BaseRadArg
Value []float64
Default []float64
}
func NewFloatListRadArg ¶
func NewFloatListRadArg( name, short, argUsage, description string, hasDefault bool, defaultValue []float64, requires, excludes []string, ) FloatListRadArg
func (*FloatListRadArg) GetType ¶
func (f *FloatListRadArg) GetType() RadArgTypeT
func (*FloatListRadArg) Register ¶
func (f *FloatListRadArg) Register(cmd *ra.Cmd, mode RegistrationMode)
func (*FloatListRadArg) SetValue ¶
func (f *FloatListRadArg) SetValue(arg string)
type FloatRadArg ¶
type FloatRadArg struct {
BaseRadArg
Value float64
Default float64
RangeConstraint *ArgRangeConstraint
}
func NewFloatRadArg ¶
func NewFloatRadArg( name, short, argUsage, description string, hasDefault bool, defaultValue float64, constraint *ArgRangeConstraint, requires, excludes []string, ) FloatRadArg
func (*FloatRadArg) GetDescription ¶
func (f *FloatRadArg) GetDescription() string
func (*FloatRadArg) GetType ¶
func (f *FloatRadArg) GetType() RadArgTypeT
func (*FloatRadArg) Register ¶
func (f *FloatRadArg) Register(cmd *ra.Cmd, mode RegistrationMode)
func (*FloatRadArg) SetValue ¶
func (f *FloatRadArg) SetValue(arg string)
type FuncInvocation ¶
type FuncInvocation struct {
// contains filtered or unexported fields
}
func NewFnInvocation ¶
func NewFnInvocation( i *Interpreter, callNode *ts.Node, funcName string, args []PosArg, namedArgs map[string]namedArg, isBuiltIn bool, ) FuncInvocation
func (FuncInvocation) GetArg ¶
func (f FuncInvocation) GetArg(name string) RadValue
func (FuncInvocation) GetBool ¶
func (f FuncInvocation) GetBool(name string) bool
func (FuncInvocation) GetFloat ¶
func (f FuncInvocation) GetFloat(name string) float64
func (FuncInvocation) GetFn ¶
func (f FuncInvocation) GetFn(name string) RadFn
func (FuncInvocation) GetInt ¶
func (f FuncInvocation) GetInt(name string) int64
func (FuncInvocation) GetIntAllowingBool ¶
func (f FuncInvocation) GetIntAllowingBool(name string) int64
func (FuncInvocation) GetList ¶
func (f FuncInvocation) GetList(name string) *RadList
func (FuncInvocation) GetMap ¶
func (f FuncInvocation) GetMap(name string) *RadMap
func (FuncInvocation) GetStr ¶
func (f FuncInvocation) GetStr(name string) RadString
func (FuncInvocation) Return ¶
func (f FuncInvocation) Return(vals ...interface{}) RadValue
func (FuncInvocation) ReturnErrf ¶
func (f FuncInvocation) ReturnErrf(code rl.Error, msg string, args ...interface{}) RadValue
type GeneralSort ¶
type HttpRequest ¶ added in v0.6.13
type HttpRequest struct {
RequestDef RequestDef
ResponseDef ResponseDef
}
type InputReader ¶ added in v0.5.59
type InputReader interface {
ReadStatement() (string, error)
SupportsMultiLine() bool
SetPrompt(primary, continuation string)
Shutdown() error
}
InputReader abstracts input handling (designed for future multi-line extension)
func NewSingleLineInputReader ¶ added in v0.5.59
func NewSingleLineInputReader() InputReader
NewSingleLineInputReader creates a new single-line input reader using RadIo
type IntListRadArg ¶
type IntListRadArg struct {
BaseRadArg
Value []int64
Default []int64
}
func NewIntListRadArg ¶
func NewIntListRadArg( name, short, argUsage, description string, hasDefault bool, defaultValue []int64, requires, excludes []string, ) IntListRadArg
func (*IntListRadArg) GetType ¶
func (f *IntListRadArg) GetType() RadArgTypeT
func (*IntListRadArg) Register ¶
func (f *IntListRadArg) Register(cmd *ra.Cmd, mode RegistrationMode)
func (*IntListRadArg) SetValue ¶
func (f *IntListRadArg) SetValue(arg string)
type IntRadArg ¶
type IntRadArg struct {
BaseRadArg
Value int64
Default int64
RangeConstraint *ArgRangeConstraint
}
func NewIntRadArg ¶
func (*IntRadArg) GetDescription ¶
func (*IntRadArg) GetType ¶
func (f *IntRadArg) GetType() RadArgTypeT
type Interpreter ¶
type Interpreter struct {
// contains filtered or unexported fields
}
func NewInterpreter ¶
func NewInterpreter(input InterpreterInput) *Interpreter
func (*Interpreter) EvaluateStatement ¶ added in v0.5.59
func (i *Interpreter) EvaluateStatement(input string) (RadValue, error)
EvaluateStatement evaluates a single statement string and returns the result This is designed for REPL use where individual statements are evaluated against a persistent interpreter environment
func (*Interpreter) GetSrc ¶
func (i *Interpreter) GetSrc() string
func (*Interpreter) GetSrcForNode ¶
func (i *Interpreter) GetSrcForNode(node *ts.Node) string
func (*Interpreter) InitArgs ¶
func (i *Interpreter) InitArgs(args []RadArg)
func (*Interpreter) InitBuiltIns ¶
func (i *Interpreter) InitBuiltIns()
func (*Interpreter) NewRadPanic ¶
func (i *Interpreter) NewRadPanic(node *ts.Node, err RadValue) *RadPanic
func (*Interpreter) RegisterWithExit ¶
func (i *Interpreter) RegisterWithExit()
func (*Interpreter) Run ¶
func (i *Interpreter) Run()
func (*Interpreter) WithTmpSrc ¶
func (i *Interpreter) WithTmpSrc(tmpSrc string, fn func())
todo this is somewhat hacky, not a fan. only use when you're extremely sure fn won't panic
type InterpreterInput ¶ added in v0.6.16
type InterpreterInput struct {
Src string
Tree *rts.RadTree
ScriptName string
InvokedCommand *ScriptCommand
}
type InvocationLogEntry ¶ added in v0.6.11
type InvocationLogEntry struct {
EpochMillis int64 `json:"epoch_millis"`
ScriptPath string `json:"script_path"`
Args []string `json:"args,omitempty"` // omitempty when include_args=false
RadVersion string `json:"rad_version"`
DurationMillis int64 `json:"duration_millis"`
}
InvocationLogEntry represents a single script execution log entry
type InvocationLoggingConfig ¶ added in v0.6.11
type InvocationType ¶ added in v0.5.59
type InvocationType int
const ( NoScript InvocationType = iota // help, version, no args ScriptFile // existing file StdinScript // "rad -" EmbeddedCommand // built-in commands Repl // interactive REPL mode )
type JsonFieldVar ¶
func NewJsonFieldVar ¶
func NewJsonFieldVar(i *Interpreter, leftNode, jsonPathNode *ts.Node) *JsonFieldVar
type JsonPath ¶
type JsonPath struct {
Segments []JsonPathSegment
}
type JsonPathSegment ¶
type JsonPathSegment struct {
Identifier string
SegmentNode *ts.Node
IdxSegments []JsonPathSegmentIdx
}
type JsonPathSegmentIdx ¶
type MockResponse ¶
type MockResponseSlice ¶
type MockResponseSlice []MockResponse
func (*MockResponseSlice) Set ¶
func (m *MockResponseSlice) Set(value string) error
func (*MockResponseSlice) String ¶
func (m *MockResponseSlice) String() string
func (*MockResponseSlice) Type ¶
func (m *MockResponseSlice) Type() string
type NullWriter ¶
type NullWriter struct{}
type PickResource ¶
type PickResource struct {
Opts []PickResourceOpt
}
type PickResourceOpt ¶
type PickResourceOptionSerde ¶
type PickResourceOptionSerde struct {
Keys []string `json:"keys"`
Values []interface{} `json:"values"`
}
type PickResourceSerde ¶
type PickResourceSerde struct {
Options []PickResourceOptionSerde `json:"options"`
}
type Printer ¶
type Printer interface {
// For Rad writers to debug their scripts. They input their debug logs with debug(). Enabled with --debug.
ScriptDebug(msg string)
// For Rad (tool) developers to debug the Rad tool, not Rad scripts. Enabled with --rad-debug.
// Rad writers should generally not need to use this.
RadDebugf(format string, args ...interface{})
// For regular output to the script user (literal string, no format interpretation)
Print(msg string)
// For regular output to the script user (with format string)
Printf(format string, args ...interface{})
// For secondary output to the user from Rad, usually to give some feedback, for example querying a URL.
// Goes to stderr.
RadStderrf(format string, args ...interface{})
// Used to print messages from the Rad script to stderr.
ScriptStderrf(format string, args ...interface{})
// For output that will be evaluated by the shell, used by --SHELL.
PrintForShellEval(msg string)
// For errors related to running the Rad script, with no token available for context.
// Exits.
ErrorExit(msg string)
// Like ErrorExit but takes an error code.
ErrorExitCode(msg string, errorCode int)
// TODO
CtxErrorExit(ctx ErrorCtx)
// TODO
CtxErrorCodeExit(ctx ErrorCtx, errorCode int)
ErrorCodeExitf(errorCode int, msgFmt string, args ...interface{})
// For errors not related to the Rad script, but to rad itself and its usage (probably misuse or rad bugs).
// Exits.
RadErrorExit(msg string)
// Similar to RadErrorExit, but prints usage after errors, and before exiting.
UsageErrorExit(msg string)
// Returns the appropriate writer for regular/standard (non-error) output.
GetStdWriter() io.Writer
}
todo make global instance, rather than passing into everything For all output to the user, except perhaps pflag-handled help/parsing errors.
func NewPrinter ¶
func NewPrinter(runner *RadRunner, isShellMode bool, isQuiet bool, isScriptDebug bool, isRadDebug bool) Printer
isShellMode directs all regular output to stderr, to avoid interfering with shell evals
isQuiet suppresses all output except shell eval prints and rad usage errors, unless isDebug is true, in which case it will also print rl errors stdout, and all debug messages
isScriptDebug will enable script debug messages isRadDebug will enable rad debug messages, and include stack traces for errors
type RadArg ¶
type RadArg interface {
GetExternalName() string
GetIdentifier() string
GetShort() string
GetArgUsage() string
GetDescription() string
DefaultAsString() string
HasNonZeroDefault() bool // todo
GetType() RadArgTypeT
Register(cmd *ra.Cmd, mode RegistrationMode)
Configured() bool // configured by the user in some way
IsDefined() bool // either configured or has a default
SetValue(value string)
IsOptional() bool
IsNullable() bool
GetNode() *ts.Node // nil if not a script arg
Hidden(bool)
IsHidden() bool
Excludes(otherArg RadArg) bool
IsVariadic() bool
}
func CreateAndRegisterGlobalFlags ¶
func CreateAndRegisterGlobalFlags() []RadArg
func CreateFlag ¶
type RadArgTypeT ¶
type RadArgTypeT int
const ( ArgStringT RadArgTypeT = iota ArgIntT ArgFloatT ArgBoolT ArgStrListT ArgIntListT ArgFloatListT ArgBoolListT )
func ToRadArgTypeT ¶
func ToRadArgTypeT(str string) RadArgTypeT
type RadBlockType ¶
type RadBlockType string
const ( RadBlock RadBlockType = "rad" RequestBlock RadBlockType = "request" DisplayBlock RadBlockType = "display" )
type RadConfig ¶ added in v0.6.11
type RadConfig struct {
InvocationLogging *InvocationLoggingConfig `toml:"invocation_logging"`
}
func DefaultRadConfig ¶ added in v0.6.11
func DefaultRadConfig() *RadConfig
func LoadRadConfig ¶ added in v0.6.11
func LoadRadConfig() *RadConfig
LoadRadConfig loads the invocation logging configuration from ~/.rad/config.toml (configurable) Returns defaults if file doesn't exist or on parse errors (with warnings)
type RadError ¶
func NewErrorStrf ¶
type RadExitHandler ¶ added in v0.6.11
type RadExitHandler struct {
// contains filtered or unexported fields
}
func NewExitHandler ¶ added in v0.6.11
func NewExitHandler(delegate func(int)) *RadExitHandler
func (*RadExitHandler) AddPreExitCallback ¶ added in v0.6.11
func (h *RadExitHandler) AddPreExitCallback(cb func())
func (*RadExitHandler) Exit ¶ added in v0.6.11
func (h *RadExitHandler) Exit(code int)
func (*RadExitHandler) SetExecuteDeferredStmtsFunc ¶ added in v0.6.11
func (h *RadExitHandler) SetExecuteDeferredStmtsFunc(f func(code int))
type RadFn ¶
type RadFn struct {
BuiltInFunc *BuiltInFunc // if this represents a built-in function
// below for non-built-in functions
ReprNode *ts.Node // representative node (can point at this for errors)
Typing *rl.TypingFnT
Stmts []ts.Node
IsBlock bool // if this is a block function or expr. Block functions can only return with a 'return' stmt.
Env *Env // for closures
}
func NewBuiltIn ¶
func NewBuiltIn(inFunc BuiltInFunc) RadFn
func (RadFn) Execute ¶
func (fn RadFn) Execute(f FuncInvocation) (out RadValue)
type RadHome ¶
var RadHomeInst *RadHome
func NewRadHome ¶
func (*RadHome) GetStashForId ¶
func (*RadHome) GetStashSub ¶
func (*RadHome) SetStashId ¶
type RadList ¶
type RadList struct {
Values []RadValue
}
func NewRadList ¶
func NewRadList() *RadList
func NewRadListFromGeneric ¶
func NewRadListFromGeneric[T any](i *Interpreter, node *ts.Node, list []T) *RadList
func (*RadList) AsActualStringList ¶
func (l *RadList) AsActualStringList(i *Interpreter, node *ts.Node) []string
requires contents to actually be strings
func (*RadList) AsStringList ¶
func (*RadList) ModifyIdx ¶
func (l *RadList) ModifyIdx(i *Interpreter, idxNode *ts.Node, value RadValue)
func (*RadList) SortAccordingToIndices ¶
func (l *RadList) SortAccordingToIndices(i *Interpreter, node *ts.Node, indices []int64)
type RadMap ¶
type RadMap struct {
// contains filtered or unexported fields
}
func NewTimeMap ¶
func (*RadMap) ContainsKey ¶
func (*RadMap) SetPrimitiveBool ¶
func (*RadMap) SetPrimitiveFloat ¶
func (*RadMap) SetPrimitiveInt ¶
func (*RadMap) SetPrimitiveInt64 ¶
func (*RadMap) SetPrimitiveList ¶
func (*RadMap) SetPrimitiveMap ¶
func (*RadMap) SetPrimitiveStr ¶
type RadPanic ¶
type RadPanic struct {
ErrV RadValue
ShellResult *shellResult // For shell command errors, contains exit code/stdout/stderr
}
type RadRunner ¶
type RadRunner struct {
// contains filtered or unexported fields
}
func NewRadRunner ¶
func NewRadRunner(runnerInput RunnerInput) *RadRunner
type RadString ¶
type RadString struct {
Segments []radStringSegment
}
func NewRadString ¶
todo should these methods be returning *RadString?
func (RadString) CopyAttrTo ¶
Copies only the attributes of the first segment. Maybe could change somehow?
func (*RadString) CopyWithAttr ¶
func (s *RadString) CopyWithAttr(attr RadTextAttr) RadString
func (*RadString) SetAttr ¶
func (s *RadString) SetAttr(attr RadTextAttr)
func (*RadString) SetSegmentsHyperlink ¶
func (*RadString) ToRuneList ¶
func (*RadString) TrimPrefix ¶
func (*RadString) TrimSuffix ¶
type RadTextAttr ¶
type RadTextAttr int
const ( PLAIN RadTextAttr = iota BLACK RED GREEN YELLOW BLUE MAGENTA CYAN WHITE ORANGE PINK BOLD ITALIC UNDERLINE )
when adding attrs, add 1) here, 2) attrEnumToStrings, 3) ToTblColor, and 4) ToFatihAttr
func AttrFromString ¶
func AttrFromString(i *Interpreter, node *ts.Node, str string) RadTextAttr
func TryColorFromString ¶
func TryColorFromString(str string) (RadTextAttr, bool)
func (RadTextAttr) AddAttrTo ¶
func (a RadTextAttr) AddAttrTo(clr *color.Color)
func (RadTextAttr) Colorize ¶
func (a RadTextAttr) Colorize(str string) string
func (RadTextAttr) String ¶
func (a RadTextAttr) String() string
func (RadTextAttr) ToTblColor ¶
func (a RadTextAttr) ToTblColor() tblwriter.Color
type RadTypeVisitor ¶
type RadTypeVisitor struct {
// contains filtered or unexported fields
}
RadTypeVisitor is my best attempt at trying to work around the fact that Go doesn't have an exhaustive switch on sealed types/enums. This visitor is verbose, but should make it easy to update existing code when adding a new type to Rad.
func NewTypeVisitor ¶
func NewTypeVisitor(i *Interpreter, node *ts.Node) *RadTypeVisitor
func NewTypeVisitorUnsafe ¶
func NewTypeVisitorUnsafe() *RadTypeVisitor
func (*RadTypeVisitor) ForBool ¶
func (v *RadTypeVisitor) ForBool(handler func(RadValue, bool)) *RadTypeVisitor
func (*RadTypeVisitor) ForDefault ¶
func (v *RadTypeVisitor) ForDefault(handler func(RadValue)) *RadTypeVisitor
func (*RadTypeVisitor) ForError ¶
func (v *RadTypeVisitor) ForError(handler func(RadValue, *RadError)) *RadTypeVisitor
func (*RadTypeVisitor) ForFloat ¶
func (v *RadTypeVisitor) ForFloat(handler func(RadValue, float64)) *RadTypeVisitor
func (*RadTypeVisitor) ForFn ¶
func (v *RadTypeVisitor) ForFn(handler func(RadValue, RadFn)) *RadTypeVisitor
func (*RadTypeVisitor) ForInt ¶
func (v *RadTypeVisitor) ForInt(handler func(RadValue, int64)) *RadTypeVisitor
func (*RadTypeVisitor) ForList ¶
func (v *RadTypeVisitor) ForList(handler func(RadValue, *RadList)) *RadTypeVisitor
func (*RadTypeVisitor) ForMap ¶
func (v *RadTypeVisitor) ForMap(handler func(RadValue, *RadMap)) *RadTypeVisitor
func (*RadTypeVisitor) ForNull ¶
func (v *RadTypeVisitor) ForNull(handler func(RadValue, RadNull)) *RadTypeVisitor
func (*RadTypeVisitor) ForString ¶
func (v *RadTypeVisitor) ForString(handler func(RadValue, RadString)) *RadTypeVisitor
func (*RadTypeVisitor) UnhandledTypeError ¶
func (v *RadTypeVisitor) UnhandledTypeError(val RadValue)
func (*RadTypeVisitor) Visit ¶
func (v *RadTypeVisitor) Visit(acceptor RadTypeVisitorAcceptor)
type RadTypeVisitorAcceptor ¶
type RadTypeVisitorAcceptor interface {
Accept(visitor *RadTypeVisitor)
}
type RadValue ¶
type RadValue struct {
// int64, float64, RadString, bool stored as values
// collections (lists, maps) stored as pointers
// lists are *RadList
// maps are *RadMap
// functions are RadFn
// nulls are RadNull
// errors are *RadError
Val interface{}
}
func ConvertToNativeTypes ¶
func ConvertToNativeTypes(i *Interpreter, node *ts.Node, val interface{}) RadValue
it was originally implemented because we might capture JSON as a list of unhandled types, but now we should be able to capture json and convert it entirely to native Rad types up front
func ConvertValuesToNativeTypes ¶
func ConvertValuesToNativeTypes(i *Interpreter, node *ts.Node, vals []interface{}) []RadValue
func TryConvertJsonToNativeTypes ¶
func TryConvertJsonToNativeTypes(i *Interpreter, node *ts.Node, maybeJsonStr string) (RadValue, error)
Convert a json interface{} into native Rad types
func (RadValue) Accept ¶
func (v RadValue) Accept(visitor *RadTypeVisitor)
func (RadValue) ModifyIdx ¶
func (v RadValue) ModifyIdx(i *Interpreter, idxNode *ts.Node, rightValue RadValue)
func (RadValue) RequireBool ¶
func (v RadValue) RequireBool(i *Interpreter, node *ts.Node) bool
func (RadValue) RequireError ¶
func (v RadValue) RequireError(i *Interpreter, node *ts.Node) *RadError
func (RadValue) RequireFloatAllowingInt ¶
func (v RadValue) RequireFloatAllowingInt(i *Interpreter, node *ts.Node) float64
func (RadValue) RequireInt ¶
func (v RadValue) RequireInt(i *Interpreter, node *ts.Node) int64
func (RadValue) RequireIntAllowingBool ¶
func (v RadValue) RequireIntAllowingBool(i *Interpreter, node *ts.Node) int64
func (RadValue) RequireList ¶
func (v RadValue) RequireList(i *Interpreter, node *ts.Node) *RadList
func (RadValue) RequireMap ¶
func (v RadValue) RequireMap(i *Interpreter, node *ts.Node) *RadMap
func (RadValue) RequireNotType ¶
func (RadValue) RequireStr ¶
func (v RadValue) RequireStr(i *Interpreter, node *ts.Node) RadString
func (RadValue) RequireType ¶
func (RadValue) ToCompatSubject ¶
func (v RadValue) ToCompatSubject(i *Interpreter) (out rl.TypingCompatVal)
func (RadValue) TruthyFalsy ¶
func (RadValue) TryGetBool ¶
func (RadValue) TryGetError ¶
func (RadValue) TryGetFloatAllowingInt ¶
func (RadValue) TryGetList ¶
type ReadlineInputReader ¶ added in v0.5.59
type ReadlineInputReader struct {
}
Future: ReadlineInputReader for enhanced input with history This interface design allows us to swap in a readline-based implementation later
type RegistrationMode ¶ added in v0.6.16
type RegistrationMode int
RegistrationMode defines how an argument should be registered on a Ra command. These modes enforce the correct combination of positional capability and Ra global behavior.
const ( // AsScriptArg: Script args on root when NO commands exist // - Positional + flag capable (flagOnly=false) // - Not a Ra global (asRaGlobal=false) AsScriptArg RegistrationMode = iota // AsCommandArg: Command-specific args on a subcommand // - Positional + flag capable (flagOnly=false) // - Not a Ra global (asRaGlobal=false) AsCommandArg // AsScriptFlagOnly: Script args on subcommands when commands exist // - Flag-only (flagOnly=true) // - Not a Ra global (asRaGlobal=false) // - Script args are shared across commands but don't interfere with command positionals AsScriptFlagOnly // AsGlobalFlag: Rad's built-in global flags (--help, --version, --color, etc.) // - Flag-only (flagOnly=true) // - Ra global (asRaGlobal=true, inherits to all subcommands) AsGlobalFlag )
type ReplSession ¶ added in v0.5.59
type ReplSession interface {
Run() error
ExecuteStatement(input string) (*ExecutionResult, error)
GetEnvironment() *Env
Shutdown() error
}
ReplSession represents the main REPL session contract
func CreateReplSession ¶ added in v0.5.59
func CreateReplSession() (ReplSession, error)
CreateReplSession creates a new REPL session with default configuration
func NewReplSession ¶ added in v0.5.59
func NewReplSession(interpreter *Interpreter, inputReader InputReader) ReplSession
NewReplSession creates a new REPL session with the given interpreter and input reader
type RequestDef ¶
func NewRequestDef ¶
func NewRequestDef(method, url string, headers map[string][]string, body *string) RequestDef
func (RequestDef) BodyReader ¶
func (r RequestDef) BodyReader() io.Reader
type Requester ¶
type Requester struct {
// contains filtered or unexported fields
}
func NewRequester ¶
func NewRequester() *Requester
func (*Requester) AddMockedResponse ¶
func (*Requester) ClearMockedResponses ¶ added in v0.6.18
func (r *Requester) ClearMockedResponses()
func (*Requester) Request ¶
func (r *Requester) Request(def RequestDef) ResponseDef
func (*Requester) RequestJson ¶
func (*Requester) SetCaptureCallback ¶ added in v0.6.13
func (r *Requester) SetCaptureCallback(cb func(HttpRequest))
type ResponseDef ¶
type ResponseDef struct {
Success bool // true if 2xx response, else false
StatusCode *int
Headers *map[string][]string
Body *string
Error *string // signifies error making request
DurationSeconds float64
}
todo we should add more e.g. reason, message
func NewResponseDef ¶
func (ResponseDef) ToRadMap ¶
func (r ResponseDef) ToRadMap(i *Interpreter, callNode *ts.Node) *RadMap
type RunnerInput ¶
type ScriptArg ¶
type ScriptArg struct {
Name string // identifier name in the script
ApiName string // name that the user will see
Decl rts.ArgDecl
Short *string
Type RadArgTypeT
Description *string
IsNullable bool // aka is optional. e.g. 'string?' syntax
HasDefaultValue bool
IsVariadic bool // whether this is a variadic argument (*options str)
EnumConstraint *[]string
RegexConstraint *regexp.Regexp
RangeConstraint *ArgRangeConstraint
RequiresConstraint []string
ExcludesConstraint []string
// first check the Type and HasDefaultValue, then get the value
DefaultString *string
DefaultStringList *[]string
DefaultInt *int64
DefaultIntList *[]int64
DefaultFloat *float64
DefaultFloatList *[]float64
DefaultBool *bool
DefaultBoolList *[]bool
}
func FromArgDecl ¶
func FromArgDecl( decl rts.ArgDecl, enumConstraint *rts.ArgEnumConstraint, regexConstraint *rts.ArgRegexConstraint, rangeConstraint *rts.ArgRangeConstraint, requiresConstraint []string, excludesConstraint []string, ) *ScriptArg
type ScriptCommand ¶ added in v0.6.16
type ScriptCommand struct {
Name string
Description *string
Args []*ScriptArg // Command-specific arguments
CallbackType rts.CallbackType
CallbackName *string // For function reference callbacks (rts.CallbackIdentifier)
CallbackLambda *ts.Node // For inline lambda callbacks (rts.CallbackLambda)
}
ScriptCommand represents a command defined in a Rad script's command: block
func FromCmdBlock ¶ added in v0.6.16
func FromCmdBlock(cmdBlock *rts.CmdBlock) (*ScriptCommand, error)
type ScriptData ¶
type ScriptData struct {
ScriptName string
Args []*ScriptArg
Commands []*ScriptCommand
Description *string
Tree *rts.RadTree
Src string
DisableGlobalOpts bool
DisableArgsBlock bool
}
func ExtractMetadata ¶
func ExtractMetadata(src string) *ScriptData
func (*ScriptData) ValidateNoErrors ¶
func (sd *ScriptData) ValidateNoErrors()
type ShellExecutor ¶ added in v0.6.13
type ShellExecutor func(invocation ShellInvocation) (string, string, int)
ShellExecutor is the function type for executing shell commands Returns: (stdout, stderr, exitCode) - only returns captured output based on invocation.Capture* fields
type ShellInvocation ¶ added in v0.6.13
type ShellInvocation struct {
Command string
CaptureStdout bool
CaptureStderr bool
IsQuiet bool
IsConfirm bool
}
ShellInvocation captures the details of a shell command invocation
type SingleLineInputReader ¶ added in v0.5.59
type SingleLineInputReader struct {
// contains filtered or unexported fields
}
SingleLineInputReader implements InputReader for single-line input (MVP) Uses RadIo abstractions for full testability
func (*SingleLineInputReader) ReadStatement ¶ added in v0.5.59
func (r *SingleLineInputReader) ReadStatement() (string, error)
ReadStatement reads a single line of input from the user
func (*SingleLineInputReader) SetPrompt ¶ added in v0.5.59
func (r *SingleLineInputReader) SetPrompt(primary, continuation string)
SetPrompt allows customizing the prompts
func (*SingleLineInputReader) Shutdown ¶ added in v0.5.59
func (r *SingleLineInputReader) Shutdown() error
Shutdown cleans up resources
func (*SingleLineInputReader) SupportsMultiLine ¶ added in v0.5.59
func (r *SingleLineInputReader) SupportsMultiLine() bool
SupportsMultiLine returns false for MVP (single-line only)
type StringListRadArg ¶
type StringListRadArg struct {
BaseRadArg
Value []string
Default []string
}
func NewStringListRadArg ¶
func NewStringListRadArg( name, short, argUsage, description string, hasDefault bool, defaultValue, requires, excludes []string, ) StringListRadArg
func (*StringListRadArg) GetType ¶
func (f *StringListRadArg) GetType() RadArgTypeT
func (*StringListRadArg) Register ¶
func (f *StringListRadArg) Register(cmd *ra.Cmd, mode RegistrationMode)
func (*StringListRadArg) SetValue ¶
func (f *StringListRadArg) SetValue(arg string)
type StringRadArg ¶
type StringRadArg struct {
BaseRadArg
Value string
Default string
EnumConstraint *[]string
RegexConstraint *regexp.Regexp
}
func NewStringRadArg ¶
func (*StringRadArg) GetDescription ¶
func (f *StringRadArg) GetDescription() string
func (*StringRadArg) GetType ¶
func (f *StringRadArg) GetType() RadArgTypeT
func (*StringRadArg) Register ¶
func (f *StringRadArg) Register(cmd *ra.Cmd, mode RegistrationMode)
func (*StringRadArg) SetValue ¶
func (f *StringRadArg) SetValue(arg string)
type TblWriter ¶
type TblWriter struct {
// contains filtered or unexported fields
}
func NewTblWriter ¶
func NewTblWriter() *TblWriter
func (*TblWriter) SetColumnColoring ¶
type Trie ¶
type Trie struct {
// contains filtered or unexported fields
}
func CreateTrie ¶
func CreateTrie(i *Interpreter, radKeywordNode *ts.Node, jsonFields []JsonFieldVar) *Trie
func (*Trie) Insert ¶
func (t *Trie) Insert(field JsonFieldVar)
func (*Trie) TraverseTrie ¶
func (t *Trie) TraverseTrie(data interface{})
Source Files
¶
- arg_types.go
- args.go
- args_helpers.go
- args_mock.go
- clock.go
- cmds.go
- command_types.go
- config.go
- consts.go
- defer.go
- env.go
- errors.go
- eval_ctx.go
- exit.go
- expr_ops.go
- flags_global.go
- func_colorize.go
- func_exit.go
- func_helpers.go
- func_matches.go
- func_multipick.go
- func_pick.go
- func_print.go
- func_rand.go
- func_range.go
- func_replace.go
- func_sleep.go
- func_split.go
- funcs.go
- funcs_internal.go
- funcs_internal_check_from_logs.go
- funcs_stat_linux.go
- global.go
- home_stash.go
- input.go
- interpreter.go
- io.go
- json_algo.go
- json_algo_trie.go
- json_path.go
- logging_invocation.go
- logging_rotation.go
- logging_rotation_unix.go
- parsed_types.go
- printer.go
- rad_block.go
- rad_time.go
- repl.go
- repl_input.go
- repl_session.go
- requester.go
- resources.go
- runner.go
- runner_usage.go
- script_meta.go
- shell.go
- slicing.go
- sorting.go
- tbl.go
- text_attr.go
- type_error.go
- type_fn.go
- type_list.go
- type_map.go
- type_null.go
- type_rad_value.go
- type_string.go
- type_visitor.go
- utils.go
- version.go