-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.go
55 lines (41 loc) · 1.37 KB
/
options.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
package sshclient
import (
"encoding/json"
"github.com/khorevaa/go-v8platform/agent/client/errors"
)
// options
func (c *AgentClient) Options(opts ...execOption) (ConfigurationOptions, error) {
var configurationOptions ConfigurationOptions
var body []byte
var e error
options := newExecOptions()
options = append(options, WithRespondCheck(successChecker(&body, &e)))
options = append(options, opts...)
_, err := c.Exec(OptionsList{}, options...)
if err != nil {
return configurationOptions, err
}
err = json.Unmarshal(body, &configurationOptions)
if err != nil {
return configurationOptions, errors.Wrapf(err, "cannot read body data")
}
return configurationOptions, nil
}
func (c *AgentClient) SetOptions(configurationOptions ConfigurationOptions, opts ...execOption) error {
setOpt := SetOptions{
OutputFormat: configurationOptions.OutputFormat,
ShowPrompt: OptionsBoolType(boolToString(configurationOptions.ShowPrompt)),
NotifyProgress: OptionsBoolType(boolToString(configurationOptions.NotifyProgress)),
NotifyProgressInterval: configurationOptions.NotifyProgressInterval,
}
var body []byte
var e error
options := newExecOptions()
options = append(options, WithRespondCheck(successChecker(&body, &e)))
options = append(options, opts...)
_, err := c.Exec(setOpt, options...)
if err != nil {
return err
}
return e
}