forked from simonleung8/cli-plugin-recorder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
84 lines (76 loc) · 1.84 KB
/
main.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package main
import (
"fmt"
"github.com/cloudfoundry/cli/plugin"
"github.com/simonleung8/cli-plugin-recorder/record"
"github.com/simonleung8/cli-plugin-recorder/replay"
)
type CLI_Recorder struct{}
func (c *CLI_Recorder) GetMetadata() plugin.PluginMetadata {
return plugin.PluginMetadata{
Name: "CLI-Recorder",
Version: plugin.VersionType{
Major: 1,
Minor: 0,
Build: 1,
},
Commands: []plugin.Command{
{
Name: "record",
HelpText: "record a set of CLI commands",
UsageDetails: plugin.Usage{
Usage: `record [COMMAND SET NAME] | -l | -n [COMMAND SET NAME] | -d [COMMAND SET NAME] | -clear
Options:
-l : to list all the record command sets
-n : to list all commands withint a set
-d : to delete a command set
-clear : clear all record commands
`,
},
},
{
Name: "replay",
Alias: "rp",
HelpText: "replay a set of recorded CLI commands",
UsageDetails: plugin.Usage{
Usage: "replay [COMMAND SET NAME]",
},
},
},
}
}
func main() {
plugin.Start(new(CLI_Recorder))
}
func (c *CLI_Recorder) Run(cliConnection plugin.CliConnection, args []string) {
if args[0] == "record" {
runRecord(cliConnection, args)
} else if args[0] == "replay" {
if len(args) > 1 {
p := replay.NewReplayCmds(cliConnection, args[1:]...)
p.Run()
} else {
fmt.Println("Provide the recorded command set name to playback")
}
}
}
func runRecord(cliConnection plugin.CliConnection, args []string) {
r := record.NewRecordCmd(cliConnection)
if len(args) == 2 {
if args[1] == "-l" {
r.ListCmdSets()
} else if args[1] == "-clear" {
r.ClearCmdSets()
} else {
r.Record(args[1])
}
} else if len(args) == 3 {
if args[1] == "-n" {
r.ListCmds(args[2])
} else if args[1] == "-d" {
r.DeleteCmdSet(args[2])
}
} else {
fmt.Println("Provide the recorded command set name to playback")
}
}