-
Notifications
You must be signed in to change notification settings - Fork 0
/
command.go
61 lines (47 loc) · 1.79 KB
/
command.go
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package cidsdk
// ExecuteCommandRequest defines model for ExecuteCommandRequest.
type ExecuteCommandRequest struct {
// CaptureOutput capture and return the output (stdout and stderr will be passed through if not set)
CaptureOutput bool `json:"capture_output,omitempty"`
// Command command
Command string `json:"command,omitempty"`
// WorkDir directory to execute the command in (default = project root)
WorkDir string `json:"work_dir,omitempty"`
// Env contains additional env properties
Env map[string]string `json:"env,omitempty"`
// Ports that will be exposed
Ports []int `json:"ports,omitempty"`
// A version Constraint for the binary used in command
Constraint []int `json:"constraint,omitempty"`
}
// ExecuteCommandResponse defines model for ExecuteCommandResponse.
type ExecuteCommandResponse struct {
// Code command exit code
Code int `json:"code,omitempty"`
// Command the command being executed
Command string `json:"command,omitempty"`
// Dir directory the command is executed in
Dir string `json:"dir,omitempty"`
// Error error message
Error string `json:"error,omitempty"`
// Stderr error output (if capture-output was request, empty otherwise)
Stderr string `json:"stderr,omitempty"`
// Stdout standard output (if capture-output was request, empty otherwise)
Stdout string `json:"stdout,omitempty"`
}
// ExecuteCommand command
func (sdk SDK) ExecuteCommand(req ExecuteCommandRequest) (*ExecuteCommandResponse, error) {
resp, err := sdk.client.R().
SetHeader("Accept", "application/json").
SetBody(req).
SetResult(&ExecuteCommandResponse{}).
SetError(&APIError{}).
Post("/v1/command/execute")
if err != nil {
return nil, err
} else if resp.IsSuccess() {
return resp.Result().(*ExecuteCommandResponse), nil
} else {
return nil, resp.Error().(*APIError)
}
}