Skip to content

Commit

Permalink
Use shlex to parse args
Browse files Browse the repository at this point in the history
  • Loading branch information
joecorall committed May 19, 2024
1 parent 225859e commit 31c0e0d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
14 changes: 13 additions & 1 deletion examples/ffmpeg/scyllaridae.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,34 @@ cmdByMimeType:
"image/jpeg":
cmd: ffmpeg
args:
- "-f"
- "%source-mime-ext"
- "-i"
- "-"
- "%args"
- "-f"
- "image2pipe"
- "-vcodec"
- "mjpeg"
- "-"
"image/png":
cmd: ffmpeg
args:
- "-f"
- "%source-mime-ext"
- "-i"
- "-"
- "%args"
- "-f"
- "image2pipe"
- "-vcodec"
- "png"
- "-"
"video/mp4":
cmd: ffmpeg
args:
- "-f"
- "%source-mime-ext"
- "-i"
- "-"
- "%args"
Expand All @@ -45,7 +57,7 @@ cmdByMimeType:
- "faststart"
- "-y"
- "-f"
- "mp4"
- "%destination-mime-ext"
- "-"
default:
cmd: ffmpeg
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.22.2

require (
github.com/go-stomp/stomp/v3 v3.1.0
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
github.com/stretchr/testify v1.9.0
gopkg.in/yaml.v3 v3.0.1
)
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ github.com/go-stomp/stomp/v3 v3.1.0 h1:JnvRJuua/fX2Lq5Ie5DXzrOL18dnzIUenCZXM6rr8
github.com/go-stomp/stomp/v3 v3.1.0/go.mod h1:ztzZej6T2W4Y6FlD+Tb5n7HQP3/O5UNQiuC169pIp10=
github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs=
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaUGG7oYTSPP8MxqL4YI3kZKwcP4=
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
Expand Down
7 changes: 6 additions & 1 deletion internal/config/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os/exec"
"strings"

"github.com/google/shlex"
"github.com/lehigh-university-libraries/scyllaridae/pkg/api"
"gopkg.in/yaml.v3"
)
Expand Down Expand Up @@ -141,7 +142,11 @@ func BuildExecCommand(message api.Payload, c *ServerConfig) (*exec.Cmd, error) {
// replace it with the args passed by the event
if a == "%args" {
if message.Attachment.Content.Args != "" {
args = append(args, message.Attachment.Content.Args)
passedArgs, err := shlex.Split(message.Attachment.Content.Args)
if err != nil {
return nil, fmt.Errorf("Error parsing args %s: %v", message.Attachment.Content.Args, err)
}
args = append(args, passedArgs...)
}
// if we have the special value of %source-mime-ext
// replace it with the source mimetype extension
Expand Down

0 comments on commit 31c0e0d

Please sign in to comment.