-
-
Notifications
You must be signed in to change notification settings - Fork 240
/
main.go
50 lines (45 loc) · 1.27 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
package generatecmd
import (
"context"
_ "embed"
"io"
"log/slog"
_ "net/http/pprof"
"github.com/a-h/templ/cmd/templ/sloghandler"
)
type Arguments struct {
FileName string
ToStdout bool
Path string
Watch bool
OpenBrowser bool
Command string
ProxyBind string
ProxyPort int
Proxy string
NotifyProxy bool
WorkerCount int
GenerateSourceMapVisualisations bool
IncludeVersion bool
IncludeTimestamp bool
LogLevel string
// PPROFPort is the port to run the pprof server on.
PPROFPort int
KeepOrphanedFiles bool
}
func Run(ctx context.Context, w io.Writer, args Arguments) (err error) {
level := slog.LevelInfo.Level()
switch args.LogLevel {
case "debug":
level = slog.LevelDebug.Level()
case "warn":
level = slog.LevelWarn.Level()
case "error":
level = slog.LevelError.Level()
}
log := slog.New(sloghandler.NewHandler(w, &slog.HandlerOptions{
AddSource: args.LogLevel == "debug",
Level: level,
}))
return NewGenerate(log, args).Run(ctx)
}