-
Notifications
You must be signed in to change notification settings - Fork 20
/
flix.go
57 lines (48 loc) · 2.15 KB
/
flix.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
package overflow
// run a script with the given code/filanem an options
func (o *OverflowState) FlixScript(filename string, opts ...OverflowInteractionOption) *OverflowScriptResult {
interaction := o.BuildInteraction(filename, "flix", opts...)
result := interaction.runScript()
if interaction.PrintOptions != nil && !interaction.NoLog {
result.Print()
}
if o.StopOnError && result.Err != nil {
result.PrintArguments(nil)
panic(result.Err)
}
return result
}
// compose interactionOptions into a new Script function
func (o *OverflowState) FlixScriptFN(outerOpts ...OverflowInteractionOption) OverflowScriptFunction {
return func(filename string, opts ...OverflowInteractionOption) *OverflowScriptResult {
outerOpts = append(outerOpts, opts...)
return o.FlixScript(filename, outerOpts...)
}
}
// compose fileName and interactionOptions into a new Script function
func (o *OverflowState) FlixScriptFileNameFN(filename string, outerOpts ...OverflowInteractionOption) OverflowScriptOptsFunction {
return func(opts ...OverflowInteractionOption) *OverflowScriptResult {
outerOpts = append(outerOpts, opts...)
return o.FlixScript(filename, outerOpts...)
}
}
// If you store this in a struct and add arguments to it it will not reset between calls
func (o *OverflowState) FlixTxFN(outerOpts ...OverflowInteractionOption) OverflowTransactionFunction {
return func(filename string, opts ...OverflowInteractionOption) *OverflowResult {
// outer has to be first since we need to be able to overwrite
opts = append(outerOpts, opts...)
return o.FlixTx(filename, opts...)
}
}
func (o *OverflowState) FlixTxFileNameFN(filename string, outerOpts ...OverflowInteractionOption) OverflowTransactionOptsFunction {
return func(opts ...OverflowInteractionOption) *OverflowResult {
// outer has to be first since we need to be able to overwrite
opts = append(outerOpts, opts...)
return o.FlixTx(filename, opts...)
}
}
// run a flix transaction with the given code/filanem an options
func (o *OverflowState) FlixTx(filename string, opts ...OverflowInteractionOption) *OverflowResult {
interaction := o.BuildInteraction(filename, "flix", opts...)
return o.sendTx(interaction)
}