Documentation
¶
Index ¶
- Constants
- Variables
- func BuildCommandEscapedString(command string, args []string) string
- func EvalIntString(ctx context.Context, input string, opts ...EvalOption) (int, error)
- func EvalString(ctx context.Context, input string, opts ...EvalOption) (string, error)
- func EvalStringFields[T any](ctx context.Context, obj T, opts ...EvalOption) (T, error)
- func ExpandReferences(ctx context.Context, input string, dataMap map[string]string) string
- func GetShellCommand(configuredShell string) string
- func JoinCommandArgs(cmd string, args []string) string
- func ParsePipedCommand(cmdString string) ([][]string, error)
- func SplitCommand(cmd string) (string, []string, error)
- func SplitCommandArgs(cmdWithArgs string) (string, []string)
- func SplitCommandWithSub(cmd string) (string, []string, error)
- type EvalOption
- type EvalOptions
Constants ¶
const ArgsDelimiter = "∯ᓰ♨"
ArgsDelimiter is the delimiter used to separate command arguments
Variables ¶
var ErrCommandIsEmpty = fmt.Errorf("command is empty")
Functions ¶
func BuildCommandEscapedString ¶
BuildCommandEscapedString constructs a single shell-ready string from a command and its arguments. It assumes that the command and arguments are already escaped.
func EvalIntString ¶
EvalIntString substitutes environment variables and commands in the input string
func EvalString ¶
EvalString substitutes environment variables and commands in the input string
func EvalStringFields ¶
func EvalStringFields[T any](ctx context.Context, obj T, opts ...EvalOption) (T, error)
EvalStringFields processes all string fields in a struct by expanding environment variables and substituting command outputs. It takes a struct value and returns a new modified struct value.
func ExpandReferences ¶
ExpandReferences finds all occurrences of ${NAME.foo.bar} in the input string, where "NAME" matches a key in the dataMap. The dataMap value is expected to be JSON. It then uses gojq to extract the .foo.bar sub-path from that JSON document. If successful, it replaces the original placeholder with the sub-path value.
If dataMap[name] is invalid JSON or the sub-path does not exist, the placeholder is left as-is (or you could handle it differently).
func GetShellCommand ¶
GetShellCommand returns the shell to use for command execution
func JoinCommandArgs ¶
JoinCommandArgs joins a command and its arguments into a single string separated by ArgsDelimiter
func ParsePipedCommand ¶
ParsePipedCommand splits a shell-style command string into a pipeline ([][]string). Each sub-slice represents a single command. Unquoted "|" tokens define the boundaries.
Example:
parsePipedCommand(`echo foo | grep foo | wc -l`) => [][]string{ {"echo", "foo"}, {"grep", "foo"}, {"wc", "-l"}, } parsePipedCommand(`echo "hello|world"`) => [][]string{ {"echo", "hello|world"} } // single command
func SplitCommandArgs ¶
SplitCommandArgs splits a command and its arguments into a command and a slice of arguments
Types ¶
type EvalOption ¶
type EvalOption func(*EvalOptions)
func OnlyReplaceVars ¶
func OnlyReplaceVars() EvalOption
func WithVariables ¶
func WithVariables(vars map[string]string) EvalOption
func WithoutExpandEnv ¶
func WithoutExpandEnv() EvalOption
func WithoutSubstitute ¶
func WithoutSubstitute() EvalOption