Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tiltfile: add shlex.quote #3720

Merged
merged 3 commits into from
Aug 26, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ require (
github.com/Shopify/sarama v1.18.0 // indirect
github.com/Shopify/toxiproxy v2.1.4+incompatible // indirect
github.com/agl/ed25519 v0.0.0-20170116200512-5312a6153412 // indirect
github.com/alessio/shellescape v1.2.2
github.com/apache/thrift v0.0.0-20171203172758-327ebb6c2b6d // indirect
github.com/bitly/go-hostpool v0.1.0 // indirect
github.com/bitly/go-simplejson v0.5.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ github.com/agl/ed25519 v0.0.0-20170116200512-5312a6153412/go.mod h1:WPjqKcmVOxf0
github.com/akavel/rsrc v0.8.0/go.mod h1:uLoCtb9J+EyAqh+26kdrTgmzRBFPGOolLWKpdxkKq+c=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/alessio/shellescape v1.2.2 h1:8LnL+ncxhWT2TR00dfJRT25JWWrhkMZXneHVWnetDZg=
github.com/alessio/shellescape v1.2.2/go.mod h1:PZAiSCk0LJaZkiCSkPv8qIobYglO3FPpyFjDCtHLS30=
github.com/apache/thrift v0.0.0-20161221203622-b2a4d4ae21c7/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ=
github.com/apache/thrift v0.0.0-20171203172758-327ebb6c2b6d h1:b/FqDLjWXDQI6XBYvWDVgEKv3xOTs68qRkuqyU37lBc=
github.com/apache/thrift v0.0.0-20171203172758-327ebb6c2b6d/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ=
Expand Down
30 changes: 30 additions & 0 deletions internal/tiltfile/shlex/shlex.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package shlex

import (
"go.starlark.net/starlark"

"github.com/tilt-dev/tilt/internal/tiltfile/starkit"

"github.com/alessio/shellescape"
)

type Extension struct{}

func NewExtension() Extension {
return Extension{}
}

func (Extension) OnStart(env *starkit.Environment) error {
return env.AddBuiltin("shlex.quote", quote)
}

func quote(thread *starlark.Thread, fn *starlark.Builtin, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error) {
var s string
err := starkit.UnpackArgs(thread, fn.Name(), args, kwargs,
"name", &s)
if err != nil {
return nil, err
}

return starlark.String(shellescape.Quote(s)), nil
}
25 changes: 25 additions & 0 deletions internal/tiltfile/shlex/shlex_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package shlex

import (
"testing"

"github.com/stretchr/testify/require"

"github.com/tilt-dev/tilt/internal/tiltfile/starkit"
)

func TestQuote(t *testing.T) {
f := starkit.NewFixture(t, NewExtension())

f.File("Tiltfile", `
s = shlex.quote("foo '$FOO'")
print(shlex.quote("foo '$FOO'"))

`)

_, err := f.ExecFile("Tiltfile")
require.NoError(t, err)

require.Equal(t, `'foo '"'"'$FOO'"'"''
`, f.PrintOutput())
}
2 changes: 2 additions & 0 deletions internal/tiltfile/tiltfile_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/tilt-dev/tilt/internal/tiltfile/k8scontext"
"github.com/tilt-dev/tilt/internal/tiltfile/os"
"github.com/tilt-dev/tilt/internal/tiltfile/secretsettings"
"github.com/tilt-dev/tilt/internal/tiltfile/shlex"
"github.com/tilt-dev/tilt/internal/tiltfile/starkit"
"github.com/tilt-dev/tilt/internal/tiltfile/starlarkstruct"
"github.com/tilt-dev/tilt/internal/tiltfile/telemetry"
Expand Down Expand Up @@ -200,6 +201,7 @@ func (s *tiltfileState) loadManifests(absFilename string, userConfigState model.
updatesettings.NewExtension(),
secretsettings.NewExtension(),
encoding.NewExtension(),
shlex.NewExtension(),
tiltextension.NewExtension(tiltextension.NewGithubFetcher(), tiltextension.NewLocalStore(filepath.Dir(absFilename))),
)
if err != nil {
Expand Down
24 changes: 24 additions & 0 deletions vendor/github.com/alessio/shellescape/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions vendor/github.com/alessio/shellescape/.travis.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions vendor/github.com/alessio/shellescape/AUTHORS

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions vendor/github.com/alessio/shellescape/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

58 changes: 58 additions & 0 deletions vendor/github.com/alessio/shellescape/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions vendor/github.com/alessio/shellescape/go.mod

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 39 additions & 0 deletions vendor/github.com/alessio/shellescape/shellescape.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ github.com/Shopify/sarama
## explicit
github.com/agl/ed25519
github.com/agl/ed25519/edwards25519
# github.com/alessio/shellescape v1.2.2
## explicit
github.com/alessio/shellescape
# github.com/apache/thrift v0.0.0-20171203172758-327ebb6c2b6d
## explicit
github.com/apache/thrift/lib/go/thrift
Expand Down