internal

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2025 License: MIT Imports: 30 Imported by: 0

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

Examples

Constants

View Source
const (
	ExecShell             = "sh"
	ExitPrompt            = "Exit"
	GithubRepo            = "https://github.com/eduardoagarcia/shef"
	PublicRecipesFilename = "recipes.tar.gz"
	PublicRecipesFolder   = "recipes"
	Version               = "v0.3.2"
)
View Source
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

View Source
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

func FormatLogs(withMetadata bool) string

FormatLogs returns all debug logs as a formatted string

func FormatText

func FormatText(text string, color Color, style Style) string

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 JoinArray

func JoinArray(arr interface{}, sep string) string

JoinArray joins array elements into a string with the specified separator

func LoadComponents added in v0.2.3

func LoadComponents(sources []string) error

LoadComponents loads components from all available sources

func Log added in v0.2.5

func Log(category, message string, metadata ...map[string]interface{})

Log adds a debug entry with the specified category and message

func LogBackgroundTask added in v0.2.5

func LogBackgroundTask(taskID, status string, metadata map[string]interface{})

LogBackgroundTask logs information about a background task

func LogCommand added in v0.2.5

func LogCommand(command string, metadata map[string]interface{})

LogCommand logs a command execution

func LogCondition added in v0.2.5

func LogCondition(condition string, result bool, metadata map[string]interface{})

LogCondition logs condition evaluation

func LogError added in v0.2.5

func LogError(message string, err error, metadata map[string]interface{})

LogError logs an error

func LogLoopEnd added in v0.2.5

func LogLoopEnd(loopType string, metadata map[string]interface{})

LogLoopEnd logs the end of a loop

func LogLoopIteration added in v0.2.5

func LogLoopIteration(loopType string, iteration int, total int, metadata map[string]interface{})

LogLoopIteration logs a loop iteration

func LogLoopStart added in v0.2.5

func LogLoopStart(loopType string, metadata map[string]interface{})

LogLoopStart logs the start of a loop

func LogOperation added in v0.2.5

func LogOperation(name, id string, metadata map[string]interface{})

LogOperation logs information about an operation

func LogOutput added in v0.2.5

func LogOutput(output string, metadata map[string]interface{})

LogOutput logs command output

func PrintLogs added in v0.2.5

func PrintLogs()

PrintLogs prints all collected logs to the console

func Run

func Run()

Run initializes and runs the Shef CLI application

func SaveLogsToFile added in v0.2.5

func SaveLogsToFile(filePath string) error

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

func (op *Operation) GetForFlow() (*ForFlow, error)

GetForFlow extracts for loop configuration from an operation

func (*Operation) GetWhileFlow

func (op *Operation) GetWhileFlow() (*WhileFlow, error)

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

type Style

type Style string

Style represents terminal text styling options

const (
	StyleNone      Style = ""
	StyleBold      Style = "bold"
	StyleDim       Style = "dim"
	StyleItalic    Style = "italic"
	StyleUnderline Style = "underline"
)

type Theme added in v0.2.4

type Theme struct {
	Saucer        string `yaml:"saucer,omitempty"`
	SaucerHead    string `yaml:"saucer_head,omitempty"`
	SaucerPadding string `yaml:"saucer_padding,omitempty"`
	BarStart      string `yaml:"bar_start,omitempty"`
	BarEnd        string `yaml:"bar_end,omitempty"`
}

type WhileFlow

type WhileFlow struct {
	Type         string `yaml:"type"`
	Condition    string `yaml:"condition"`
	ProgressMode bool   `yaml:"progress_mode,omitempty"`
}

WhileFlow defines the structure for a while loop control flow

func (*WhileFlow) GetType

func (w *WhileFlow) GetType() string

GetType returns the control flow type

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳