package workspace

import (
	"fmt"
	"strings"
)

// ShellQuote returns value single-quoted for bash, escaping embedded quotes.
func ShellQuote(value string) string {
	return "'" + strings.ReplaceAll(value, "'", `'"'"'`) + "'"
}

// FormatStepError wraps err with an action label and trimmed on-guest log.
func FormatStepError(action string, err error, log string) error {
	log = strings.TrimSpace(log)
	if log == "" {
		return fmt.Errorf("%s: %w", action, err)
	}
	return fmt.Errorf("%s: %w: %s", action, err, log)
}
