forked from toolshed/abra
.gitea
cli
app
catalogue
internal
backup.go
cli.go
command.go
deploy.go
errors.go
list.go
new.go
recipe.go
validate.go
recipe
record
server
updater
cli.go
cmd
pkg
scripts
tests
.dockerignore
.drone.yml
.e2e.env.sample
.envrc.sample
.gitignore
.goreleaser.yml
AUTHORS.md
Dockerfile
LICENSE
Makefile
README.md
go.mod
go.sum
renovate.json
36 lines
693 B
Go
36 lines
693 B
Go
package internal
|
|
|
|
import (
|
|
"strings"
|
|
)
|
|
|
|
// SafeSplit splits up a string into a list of commands safely.
|
|
func SafeSplit(s string) []string {
|
|
split := strings.Split(s, " ")
|
|
|
|
var result []string
|
|
var inquote string
|
|
var block string
|
|
for _, i := range split {
|
|
if inquote == "" {
|
|
if strings.HasPrefix(i, "'") || strings.HasPrefix(i, "\"") {
|
|
inquote = string(i[0])
|
|
block = strings.TrimPrefix(i, inquote) + " "
|
|
} else {
|
|
result = append(result, i)
|
|
}
|
|
} else {
|
|
if !strings.HasSuffix(i, inquote) {
|
|
block += i + " "
|
|
} else {
|
|
block += strings.TrimSuffix(i, inquote)
|
|
inquote = ""
|
|
result = append(result, block)
|
|
block = ""
|
|
}
|
|
}
|
|
}
|
|
|
|
return result
|
|
}
|