-
Notifications
You must be signed in to change notification settings - Fork 204
/
simulation.go
54 lines (42 loc) · 1.27 KB
/
simulation.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
package cmd
import (
"fmt"
"github.com/SpectoLabs/hoverfly/hoverctl/configuration"
"github.com/SpectoLabs/hoverfly/hoverctl/wrapper"
"github.com/spf13/cobra"
)
var simulationCmd = &cobra.Command{
Use: "simulation",
Short: "Manage the simulation for Hoverfly",
Long: `
This allows you to manage simulation data in Hoverfly.
`,
}
var addSimulationCmd = &cobra.Command{
Use: "add [path to simulations]",
Short: "Add one or more simulations into Hoverfly",
Long: `
Adds one or more simulation files to Hoverfly to the
existing simulation data.
Any request/response pairs that have an identical request
to those in the existing data will be discarded with a
warning message.
You may provide an absolute or relative path to each
simulation file.
`,
Run: func(cmd *cobra.Command, args []string) {
checkTargetAndExit(target)
checkArgAndExit(args, "You have not provided a path to simulation", "simulation add")
for _, arg := range args {
simulationData, err := configuration.ReadFile(arg)
handleIfError(err)
err = wrapper.AddSimulation(*target, string(simulationData))
handleIfError(err)
fmt.Println("Successfully added simulation from", arg)
}
},
}
func init() {
RootCmd.AddCommand(simulationCmd)
simulationCmd.AddCommand(addSimulationCmd)
}