/
flowimpl-var.go
61 lines (48 loc) · 1.28 KB
/
flowimpl-var.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 main
import (
"errors"
"fmt"
"github.com/jinzhu/copier"
"reflect"
"strings"
)
type FlowImplVar FlowImplBase
func (impl *FlowImplVar) Type() FlowImplType {
return FlowImplTypeOP
}
func (impl *FlowImplVar) Usage() string {
return impl.Name() + " $variable <string> Define $variable with value <string>"
}
func (impl *FlowImplVar) Do(args...interface{}) error {
browser := args[0].(*Browser)
variableName := impl.command.GetFieldString(0)
variableValue := impl.command.GetFieldString(1)
if strings.HasPrefix(variableName, "$") == false {
return errors.New(fmt.Sprintf("%s is not a valid variable.", variableName))
}
browser.SetVariable(variableName, variableValue)
return nil
}
//go:generate make IMPL_TYPE=FlowImplVar gen-impl
func init() {
flowImpl := func() IFlowImpl {
return &FlowImplVar{}
}()
registerFlow(flowImpl)
}
func (impl *FlowImplVar) Name() string {
interfaceName := reflect.TypeOf(impl).String()
commandName := strings.Split(interfaceName, "FlowImpl")[1]
return strings.ToLower(commandName)
}
func (impl *FlowImplVar) SetCommand(command *FlowCommand) {
impl.command = command
}
func (impl *FlowImplVar) Command() *FlowCommand {
return impl.command
}
func (impl *FlowImplVar) Clone() IFlowImpl {
c := &FlowImplVar{}
_ = copier.Copy(c, impl)
return c
}