-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
106 lines (95 loc) · 2.43 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package main
import (
"fmt"
"log"
"net"
"runtime/debug"
"strconv"
"strings"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/promwish"
"github.com/charmbracelet/ssh"
"github.com/charmbracelet/wish"
"github.com/charmbracelet/wish/activeterm"
bm "github.com/charmbracelet/wish/bubbletea"
lm "github.com/charmbracelet/wish/logging"
"github.com/charmbracelet/wishlist"
"github.com/maaslalani/confetty/confetti"
"github.com/maaslalani/confetty/fireworks"
"github.com/prometheus/client_golang/prometheus"
"github.com/spf13/pflag"
)
// nolint: gomnd
var (
listen = pflag.String("listen", "localhost", "address to listen to")
port = pflag.Int("port", 2222, "port to listen on")
metricsPort = pflag.Int("metrics-port", 9222, "port to listen on")
)
const (
effectConfetti = "confetti"
effectFireworks = "fireworks"
)
func main() {
pflag.Parse()
version := "devel"
if info, ok := debug.ReadBuildInfo(); ok && info.Main.Sum != "" {
version = info.Main.Version
}
log.Printf("Running confettysh %s", version)
go promwish.Listen(net.JoinHostPort(*listen, strconv.Itoa(*metricsPort)))
cfg := &wishlist.Config{
Listen: *listen,
Port: int64(*port),
Factory: func(e wishlist.Endpoint) (*ssh.Server, error) {
// nolint: wrapcheck
return wish.NewServer(
wish.WithAddress(e.Address),
wish.WithHostKeyPath(fmt.Sprintf(".ssh/%s", strings.ToLower(e.Name))),
wish.WithMiddleware(
append(
e.Middlewares,
promwish.MiddlewareRegistry(
prometheus.DefaultRegisterer,
prometheus.Labels{
"app": e.Name,
},
promwish.DefaultCommandFn,
),
lm.Middleware(),
activeterm.Middleware(),
)...,
),
)
},
Endpoints: []*wishlist.Endpoint{
{
Name: "Confetti",
Middlewares: []wish.Middleware{
bm.Middleware(teaHandler(effectConfetti)),
},
},
{
Name: "Fireworks",
Middlewares: []wish.Middleware{
bm.Middleware(teaHandler(effectFireworks)),
},
},
},
}
// start all the servers
if err := wishlist.Serve(cfg); err != nil {
log.Fatalln(err)
}
}
func teaHandler(effect string) func(s ssh.Session) (tea.Model, []tea.ProgramOption) {
return func(_ ssh.Session) (tea.Model, []tea.ProgramOption) {
var m tea.Model
switch effect {
case effectConfetti:
m = confetti.InitialModel()
case effectFireworks:
m = fireworks.InitialModel()
}
return m, []tea.ProgramOption{tea.WithAltScreen()}
}
}