Skip to content

Commit

Permalink
feat: add shellescape function
Browse files Browse the repository at this point in the history
  • Loading branch information
srevinsaju committed Nov 1, 2023
1 parent b189b51 commit 2452e0f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
8 changes: 3 additions & 5 deletions .github/workflows/docker-publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,10 @@ jobs:

# Install the cosign tool except on PR
# https://github.com/sigstore/cosign-installer
- name: Install cosign
if: github.event_name != 'pull_request'
uses: sigstore/cosign-installer@f3c664df7af409cb4873aa5068053ba9d61a57b6 #v2.6.0
- name: Install Cosign
uses: sigstore/[email protected]
with:
cosign-release: 'v1.13.1'

cosign-release: 'v2.1.1'

# Workaround: https://github.com/docker/build-push-action/issues/461
- name: Setup Docker buildx
Expand Down
3 changes: 2 additions & 1 deletion internal/ci/conductor_hcl.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ func CreateEvalContext(cfg ConductorConfig, process Process) *hcl.EvalContext {
"yamlencode": yaml.YAMLEncodeFunc,
"zipmap": stdlib.ZipmapFunc,

"stripansi": ui.StripAnsiFunc,
"stripansi": ui.StripAnsiFunc,
"shellescape": ui.ShellEscapeFunc,

"ansifmt": ui.AnsiFunc,
"env": function.New(&function.Spec{
Expand Down
15 changes: 15 additions & 0 deletions internal/ui/colors.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ui
import (
"fmt"
"github.com/acarl005/stripansi"
"github.com/alessio/shellescape"
"github.com/fatih/color"
"github.com/zclconf/go-cty/cty"
"github.com/zclconf/go-cty/cty/function"
Expand Down Expand Up @@ -76,6 +77,20 @@ var StripAnsiFunc = function.New(&function.Spec{
},
})

var ShellEscapeFunc = function.New(&function.Spec{
Params: []function.Parameter{
{
Name: "message",
Type: cty.String,
},
},
Type: function.StaticReturnType(cty.String),
Impl: func(args []cty.Value, retType cty.Type) (cty.Value, error) {
message := args[0].AsString()
return cty.StringVal(shellescape.Quote(message)), nil
},

Check warning on line 91 in internal/ui/colors.go

View check run for this annotation

Codecov / codecov/patch

internal/ui/colors.go#L88-L91

Added lines #L88 - L91 were not covered by tests
})

func Color(color string, message string) string {
switch color {
case "green":
Expand Down

0 comments on commit 2452e0f

Please sign in to comment.