-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
83 lines (72 loc) · 1.69 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
package main
import (
"os"
"github.com/cloudfoundry/cli/cf/terminal"
"github.com/cloudfoundry/cli/flags"
"github.com/cloudfoundry/cli/flags/flag"
"github.com/cloudfoundry/cli/plugin"
"github.com/jtuchscherer/nozzle-plugin/firehose"
)
type NozzlerCmd struct {
ui terminal.UI
}
func (c *NozzlerCmd) GetMetadata() plugin.PluginMetadata {
return plugin.PluginMetadata{
Name: "FirehosePlugin",
Version: plugin.VersionType{
Major: 0,
Minor: 4,
Build: 0,
},
MinCliVersion: plugin.VersionType{
Major: 0,
Minor: 3,
Build: 0,
},
Commands: []plugin.Command{
{
Name: "nozzle",
HelpText: "Command to print out messages from the firehose",
UsageDetails: plugin.Usage{
Usage: "cf nozzle",
Options: map[string]string{
"debug": "true to enable debugging",
},
},
},
},
}
}
func setupFlags() map[string]flags.FlagSet {
fs := make(map[string]flags.FlagSet)
fs["debug"] = &cliFlags.BoolFlag{Name: "debug", Usage: "used for debugging"}
return fs
}
func main() {
plugin.Start(new(NozzlerCmd))
}
func (c *NozzlerCmd) Run(cliConnection plugin.CliConnection, args []string) {
var debug bool
if args[0] != "nozzle" {
return
}
c.ui = terminal.NewUI(os.Stdin, terminal.NewTeePrinter())
fc := flags.NewFlagContext(setupFlags())
err := fc.Parse(args[1:]...)
if err != nil {
c.ui.Failed(err.Error())
}
if fc.IsSet("debug") {
debug = fc.Bool("debug")
}
dopplerEndpoint, err := cliConnection.DopplerEndpoint()
if err != nil {
c.ui.Failed(err.Error())
}
authToken, err := cliConnection.AccessToken()
if err != nil {
c.ui.Failed(err.Error())
}
client := firehose.NewClient(authToken, dopplerEndpoint, debug, c.ui)
client.Start()
}