Documentation
¶
Overview ¶
Example (RenderTemplate) ¶
ExampleRenderTemplate demonstrates how to use the renderTemplate function
vars := map[string]interface{}{ "name": "World", } result, err := renderTemplate("Hello, {{.name}}!", vars) if err != nil { fmt.Println("Error:", err) return } fmt.Println(result)
Output:
Index ¶
- Constants
- func DecreaseIndent()
- func ExecuteFor(op Operation, forFlow *ForFlow, ctx *ExecutionContext, depth int, ...) (bool, error)
- func ExecuteForEach(op Operation, forEach *ForEachFlow, ctx *ExecutionContext, depth int, ...) (bool, error)
- func ExecuteWhile(op Operation, whileFlow *WhileFlow, ctx *ExecutionContext, depth int, ...) (bool, error)
- func FormatLogs(withMetadata bool) string
- func FormatText(text string, color Color, style Style) string
- func IncreaseIndent()
- func InitDebugLogger(isEnabled bool)
- func IsDebugEnabled() bool
- func JoinArray(arr interface{}, sep string) string
- func LoadComponents(sources []string) error
- func Log(category, message string, metadata ...map[string]interface{})
- func LogBackgroundTask(taskID, status string, metadata map[string]interface{})
- func LogCommand(command string, metadata map[string]interface{})
- func LogCondition(condition string, result bool, metadata map[string]interface{})
- func LogError(message string, err error, metadata map[string]interface{})
- func LogLoopEnd(loopType string, metadata map[string]interface{})
- func LogLoopIteration(loopType string, iteration int, total int, metadata map[string]interface{})
- func LogLoopStart(loopType string, metadata map[string]interface{})
- func LogOperation(name, id string, metadata map[string]interface{})
- func LogOutput(output string, metadata map[string]interface{})
- func PrintLogs()
- func Run()
- func SaveLogsToFile(filePath string) error
- func TableFuncMap() map[string]interface{}
- type BackgroundTask
- type BackgroundTaskStatus
- type Color
- type Component
- type ComponentInput
- type ComponentRegistry
- type DebugEntry
- type DebugLogger
- type ExecutionContext
- type File
- type ForEachFlow
- type ForFlow
- type LoopContext
- type Operation
- type ProgressBar
- type ProgressBarOptions
- type Prompt
- type PromptValidator
- type Recipe
- type Style
- type Theme
- type WhileFlow
Examples ¶
Constants ¶
const ( ExecShell = "sh" ExitPrompt = "Exit" GithubRepo = "https://github.com/eduardoagarcia/shef" PublicRecipesFilename = "recipes.tar.gz" PublicRecipesFolder = "recipes" Version = "v0.3.2" )
const ( CategoryRecipe = "RECIPE" CategoryOperation = "OPERATION" CategoryCommand = "COMMAND" CategoryOutput = "OUTPUT" CategoryCondition = "CONDITION" CategoryPrompt = "PROMPT" CategoryComponent = "COMPONENT" CategoryControlFlow = "CONTROL_FLOW" CategoryLoop = "LOOP" CategoryBackground = "BACKGROUND" CategoryTemplate = "TEMPLATE" CategoryTransform = "TRANSFORM" CategoryFileSystem = "FILE_SYSTEM" CategoryInit = "INIT" CategoryError = "ERROR" )
Categories for debug logs
const (
LogHeader = "=== DEBUG LOGS ==="
)
Variables ¶
This section is empty.
Functions ¶
func DecreaseIndent ¶ added in v0.2.5
func DecreaseIndent()
DecreaseIndent decreases the indentation level for logs
func ExecuteFor ¶
func ExecuteFor(op Operation, forFlow *ForFlow, ctx *ExecutionContext, depth int, executeOp func(Operation, int) (bool, error)) (bool, error)
ExecuteFor runs a for loop with the given parameters
func ExecuteForEach ¶
func ExecuteForEach(op Operation, forEach *ForEachFlow, ctx *ExecutionContext, depth int, executeOp func(Operation, int) (bool, error)) (bool, error)
ExecuteForEach runs a foreach loop with the given parameters
func ExecuteWhile ¶
func ExecuteWhile(op Operation, whileFlow *WhileFlow, ctx *ExecutionContext, depth int, executeOp func(Operation, int) (bool, error)) (bool, error)
ExecuteWhile runs a while loop with the given parameters
func FormatLogs ¶ added in v0.2.5
FormatLogs returns all debug logs as a formatted string
func FormatText ¶
FormatText applies color and style formatting to text for terminal output
func IncreaseIndent ¶ added in v0.2.5
func IncreaseIndent()
IncreaseIndent increases the indentation level for logs
func InitDebugLogger ¶ added in v0.2.5
func InitDebugLogger(isEnabled bool)
InitDebugLogger initializes the debug logger
func IsDebugEnabled ¶ added in v0.2.5
func IsDebugEnabled() bool
IsDebugEnabled returns whether debug logging is enabled
func LoadComponents ¶ added in v0.2.3
LoadComponents loads components from all available sources
func LogBackgroundTask ¶ added in v0.2.5
LogBackgroundTask logs information about a background task
func LogCommand ¶ added in v0.2.5
LogCommand logs a command execution
func LogCondition ¶ added in v0.2.5
LogCondition logs condition evaluation
func LogLoopEnd ¶ added in v0.2.5
LogLoopEnd logs the end of a loop
func LogLoopIteration ¶ added in v0.2.5
LogLoopIteration logs a loop iteration
func LogLoopStart ¶ added in v0.2.5
LogLoopStart logs the start of a loop
func LogOperation ¶ added in v0.2.5
LogOperation logs information about an operation
func PrintLogs ¶ added in v0.2.5
func PrintLogs()
PrintLogs prints all collected logs to the console
func SaveLogsToFile ¶ added in v0.2.5
SaveLogsToFile saves all collected logs to a file
func TableFuncMap ¶ added in v0.2.5
func TableFuncMap() map[string]interface{}
TableFuncMap returns template functions for table rendering
Types ¶
type BackgroundTask ¶
type BackgroundTask struct { ID string Command string Status BackgroundTaskStatus Output string Error string }
BackgroundTask represents an asynchronous command execution
type BackgroundTaskStatus ¶
type BackgroundTaskStatus string
BackgroundTaskStatus represents the current state of a background task
const ( TaskPending BackgroundTaskStatus = "pending" TaskComplete BackgroundTaskStatus = "complete" TaskFailed BackgroundTaskStatus = "failed" TaskUnknown BackgroundTaskStatus = "unknown" )
Background task status constants.
type Color ¶
type Color string
Color represents terminal text colors
const ( ColorNone Color = "" ColorBlack Color = "black" ColorRed Color = "red" ColorGreen Color = "green" ColorYellow Color = "yellow" ColorBlue Color = "blue" ColorMagenta Color = "magenta" ColorCyan Color = "cyan" ColorWhite Color = "white" BgColorBlack Color = "bg-black" BgColorRed Color = "bg-red" BgColorGreen Color = "bg-green" BgColorYellow Color = "bg-yellow" BgColorBlue Color = "bg-blue" BgColorMagenta Color = "bg-magenta" BgColorCyan Color = "bg-cyan" BgColorWhite Color = "bg-white" )
type Component ¶ added in v0.2.3
type Component struct { ID string `yaml:"id"` Name string `yaml:"name"` Description string `yaml:"description,omitempty"` Inputs []ComponentInput `yaml:"inputs,omitempty"` Operations []Operation `yaml:"operations"` }
Component defines a reusable set of operations
type ComponentInput ¶ added in v0.2.7
type ComponentInput struct { ID string `yaml:"id"` Name string `yaml:"name"` Description string `yaml:"description,omitempty"` Required bool `yaml:"required,omitempty"` Default interface{} `yaml:"default,omitempty"` }
ComponentInput defines an input parameter for a component
type ComponentRegistry ¶ added in v0.2.3
type ComponentRegistry struct {
// contains filtered or unexported fields
}
ComponentRegistry manages component loading and retrieval
func (*ComponentRegistry) Clear ¶ added in v0.2.3
func (cr *ComponentRegistry) Clear()
Clear empties the registry
func (*ComponentRegistry) Get ¶ added in v0.2.3
func (cr *ComponentRegistry) Get(id string) (Component, bool)
Get retrieves a component by ID
func (*ComponentRegistry) Register ¶ added in v0.2.3
func (cr *ComponentRegistry) Register(component Component)
Register adds a component to the registry
type DebugEntry ¶ added in v0.2.5
type DebugEntry struct { Timestamp time.Time Category string Message string Indentation int Metadata map[string]interface{} }
DebugEntry represents a single debug log entry
type DebugLogger ¶ added in v0.2.5
type DebugLogger struct {
// contains filtered or unexported fields
}
DebugLogger handles the collection and display of debug logs
type ExecutionContext ¶
type ExecutionContext struct { Data string Vars map[string]interface{} OperationOutputs map[string]string OperationResults map[string]bool ProgressMode bool BackgroundTasks map[string]*BackgroundTask BackgroundMutex sync.RWMutex BackgroundWg sync.WaitGroup OperationMutex sync.RWMutex LoopStack []*LoopContext CurrentLoopIdx int ExecutedOperationsByComponent map[string][]string // contains filtered or unexported fields }
ExecutionContext maintains state during recipe execution
type File ¶
type File struct { Recipes []Recipe `yaml:"recipes"` Components []Component `yaml:"components,omitempty"` }
File represents a collection of recipes
type ForEachFlow ¶
type ForEachFlow struct { Type string `yaml:"type"` Collection string `yaml:"collection"` As string `yaml:"as"` ProgressMode bool `yaml:"progress_mode,omitempty"` ProgressBar bool `yaml:"progress_bar,omitempty"` ProgressBarOpts *ProgressBarOptions `yaml:"progress_bar_options,omitempty"` }
ForEachFlow defines the structure for a foreach loop control flow
func (*ForEachFlow) GetType ¶
func (f *ForEachFlow) GetType() string
GetType returns the control flow type
type ForFlow ¶
type ForFlow struct { Type string `yaml:"type"` Count string `yaml:"count"` Variable string `yaml:"variable"` ProgressMode bool `yaml:"progress_mode,omitempty"` ProgressBar bool `yaml:"progress_bar,omitempty"` ProgressBarOpts *ProgressBarOptions `yaml:"progress_bar_options,omitempty"` }
ForFlow defines the structure for a for loop control flow
type LoopContext ¶ added in v0.2.3
type LoopContext struct { ID string StartTime time.Time Duration time.Duration Type string Depth int }
LoopContext tracks state for a specific loop
type Operation ¶
type Operation struct { Name string `yaml:"name"` ID string `yaml:"id,omitempty"` Uses string `yaml:"uses,omitempty"` With map[string]interface{} `yaml:"with,omitempty"` Command string `yaml:"command,omitempty"` ControlFlow interface{} `yaml:"control_flow,omitempty"` Operations []Operation `yaml:"operations,omitempty"` ExecutionMode string `yaml:"execution_mode,omitempty"` OutputFormat string `yaml:"output_format,omitempty"` Silent bool `yaml:"silent,omitempty"` Condition string `yaml:"condition,omitempty"` OnSuccess string `yaml:"on_success,omitempty"` OnFailure string `yaml:"on_failure,omitempty"` Transform string `yaml:"transform,omitempty"` RawCommand bool `yaml:"raw_command,omitempty"` UserShell bool `yaml:"user_shell,omitempty"` Prompts []Prompt `yaml:"prompts,omitempty"` Break bool `yaml:"break,omitempty"` Exit bool `yaml:"exit,omitempty"` Cleanup interface{} `yaml:"cleanup,omitempty"` Workdir string `yaml:"workdir,omitempty"` ComponentInstanceID string `yaml:"-"` IsComponentOutputCollector bool `yaml:"-"` }
Operation defines a single executable step in a recipe
func ExpandComponentReferences ¶ added in v0.2.3
func ExpandComponentReferences(operations []Operation, opMap map[string]Operation) ([]Operation, error)
ExpandComponentReferences recursively replaces component references with their operations
func (*Operation) GetForEachFlow ¶
func (op *Operation) GetForEachFlow() (*ForEachFlow, error)
GetForEachFlow extracts foreach loop configuration from an operation
func (*Operation) GetForFlow ¶
GetForFlow extracts for loop configuration from an operation
func (*Operation) GetWhileFlow ¶
GetWhileFlow extracts while loop configuration from an operation
type ProgressBar ¶ added in v0.2.4
type ProgressBar struct {
// contains filtered or unexported fields
}
func CreateProgressBar ¶ added in v0.2.4
func CreateProgressBar(total int, opName string, opts *ProgressBarOptions) *ProgressBar
CreateProgressBar creates a new progress bar with the given total, operation name, and options
func (*ProgressBar) Complete ¶ added in v0.2.4
func (p *ProgressBar) Complete()
Complete marks the progress bar as finished
func (*ProgressBar) Increment ¶ added in v0.2.4
func (p *ProgressBar) Increment()
Increment adds 1 to the progress bar
func (*ProgressBar) Update ¶ added in v0.2.4
func (p *ProgressBar) Update(message string)
Update changes the description of the progress bar
type ProgressBarOptions ¶ added in v0.2.4
type ProgressBarOptions struct { Width int `yaml:"width,omitempty"` Description string `yaml:"description,omitempty"` Theme *Theme `yaml:"theme,omitempty"` ShowCount bool `yaml:"show_count,omitempty"` ShowPercentage bool `yaml:"show_percentage,omitempty"` ShowElapsedTime bool `yaml:"show_elapsed_time,omitempty"` ShowIterationSpeed bool `yaml:"show_iteration_speed,omitempty"` RefreshRate float64 `yaml:"refresh_rate,omitempty"` MessageTemplate string `yaml:"message_template,omitempty"` }
func ParseProgressBarOptions ¶ added in v0.2.4
func ParseProgressBarOptions(optsMap map[string]interface{}) *ProgressBarOptions
ParseProgressBarOptions converts a map of interface{} to a ProgressBarOptions struct
type Prompt ¶
type Prompt struct { Name string `yaml:"name"` ID string `yaml:"id,omitempty"` Type string `yaml:"type"` Message string `yaml:"message"` Default string `yaml:"default,omitempty"` Options []string `yaml:"options,omitempty"` Descriptions map[string]string `yaml:"descriptions,omitempty"` SourceOp string `yaml:"source_operation,omitempty"` SourceTransform string `yaml:"source_transform,omitempty"` MinValue int `yaml:"min_value,omitempty"` MaxValue int `yaml:"max_value,omitempty"` Required bool `yaml:"required,omitempty"` FileExtensions []string `yaml:"file_extensions,omitempty"` MultipleLimit int `yaml:"multiple_limit,omitempty"` EditorCmd string `yaml:"editor_cmd,omitempty"` HelpText string `yaml:"help_text,omitempty"` Validators []PromptValidator `yaml:"validators,omitempty"` }
Prompt defines interactive user input required during recipe execution
type PromptValidator ¶
type PromptValidator struct { Type string `yaml:"type"` Pattern string `yaml:"pattern,omitempty"` Message string `yaml:"message,omitempty"` Min int `yaml:"min,omitempty"` Max int `yaml:"max,omitempty"` }
PromptValidator defines validation rules for prompt inputs
type Recipe ¶
type Recipe struct { Name string `yaml:"name"` Description string `yaml:"description"` Category string `yaml:"category,omitempty"` Author string `yaml:"author,omitempty"` Help string `yaml:"help,omitempty"` Vars map[string]interface{} `yaml:"vars,omitempty"` Workdir string `yaml:"workdir,omitempty"` Operations []Operation `yaml:"operations"` }
Recipe defines a Shef recipe with its metadata and operations