-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
54 lines (44 loc) · 1.15 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
package main
import (
"log"
"os"
"github.com/fullpipe/herald/place"
"github.com/fullpipe/herald/target"
"github.com/urfave/cli/v2"
)
func main() {
places := []place.Place{&place.Nowhere{}, &place.Git{}, &place.Gitlab{}}
targets := []target.Target{&target.Cli{}, &target.Grafana{}, &target.Slack{}}
app := cli.NewApp()
app.Usage = "Notify someone from some place about your success"
app.UsageText = "herald PLACE [place options] TARGET [target options]"
for _, pl := range places {
subCommands := []*cli.Command{}
for _, t := range targets {
subCommands = append(subCommands, &cli.Command{
Name: t.Name(),
Usage: t.Usage(),
Flags: t.Flags(),
Action: func(pl place.Place, t target.Target) func(c *cli.Context) error {
return func(c *cli.Context) error {
meta, err := pl.Metadata()
if err != nil {
return err
}
return t.Send(meta)
}
}(pl, t),
})
}
app.Commands = append(app.Commands, &cli.Command{
Name: pl.Name(),
Usage: pl.Usage(),
Flags: pl.Flags(),
Subcommands: subCommands,
})
}
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}