forked from adriancooney/await
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcommand.go
More file actions
36 lines (31 loc) · 655 Bytes
/
command.go
File metadata and controls
36 lines (31 loc) · 655 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package main
import (
"context"
"fmt"
"net/url"
"os/exec"
"strings"
)
type commandResource struct {
url.URL
}
func (r *commandResource) Await(ctx context.Context) error {
cmdString, err := url.QueryUnescape(r.URL.Path)
if err != nil {
return err
}
// TODO(uwe): Splitting by space is brittle
cmdParts := strings.SplitN(cmdString, " ", 2)
if len(cmdParts) == 0 {
return fmt.Errorf("empty command")
}
cmd := cmdParts[0]
args := cmdParts[1:]
if err := exec.CommandContext(ctx, cmd, args...).Run(); err != nil {
if exitErr, ok := err.(*exec.ExitError); ok {
return &unavailabilityError{exitErr}
}
return err
}
return nil
}