mirror of
https://github.com/go-task/task.git
synced 2025-08-10 22:42:19 +02:00
Add shellQuote
template function
This commit is contained in:
@@ -2,6 +2,9 @@
|
||||
|
||||
## Unreleased
|
||||
|
||||
- A new `shellQuote` was added to the template system
|
||||
(`{{shellQuote "a string"}}`) to ensure a string is safe for use in shell
|
||||
([mvdan/sh#727](https://github.com/mvdan/sh/pull/727), [mvdan/sh#737](https://github.com/mvdan/sh/pull/737), [Documentation](https://pkg.go.dev/mvdan.cc/sh/v3@v3.4.0/syntax#Quote))
|
||||
- In this version [mvdan.cc/sh](https://github.com/mvdan/sh) was upgraded
|
||||
with some small fixes and features
|
||||
- The `read -p` flag is now supported
|
||||
|
@@ -639,6 +639,9 @@ Task also adds the following functions:
|
||||
converts a string from `/` path format to `\`.
|
||||
- `exeExt`: Returns the right executable extension for the current OS
|
||||
(`".exe"` for Windows, `""` for others).
|
||||
- `shellQuote`: Quotes a string to make it safe for use in shell scripts.
|
||||
Task uses [this Go function](https://pkg.go.dev/mvdan.cc/sh/v3@v3.4.0/syntax#Quote)
|
||||
for this. The Bash dialect is assumed.
|
||||
|
||||
Example:
|
||||
|
||||
|
@@ -6,7 +6,8 @@ import (
|
||||
"strings"
|
||||
"text/template"
|
||||
|
||||
"github.com/go-task/slim-sprig"
|
||||
sprig "github.com/go-task/slim-sprig"
|
||||
"mvdan.cc/sh/v3/syntax"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -37,6 +38,9 @@ func init() {
|
||||
}
|
||||
return ""
|
||||
},
|
||||
"shellQuote": func(str string) (string, error) {
|
||||
return syntax.Quote(str, syntax.LangBash)
|
||||
},
|
||||
// IsSH is deprecated.
|
||||
"IsSH": func() bool { return true },
|
||||
}
|
||||
|
Reference in New Issue
Block a user