-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmain.go
More file actions
75 lines (65 loc) · 1.77 KB
/
main.go
File metadata and controls
75 lines (65 loc) · 1.77 KB
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
package main
import (
stdCtx "context"
"errors"
"fmt"
"os"
"slices"
"github.com/google/uuid"
"github.com/flowexec/flow/cmd"
"github.com/flowexec/flow/internal/io"
"github.com/flowexec/flow/pkg/cli"
"github.com/flowexec/flow/pkg/context"
"github.com/flowexec/flow/pkg/filesystem"
"github.com/flowexec/flow/pkg/logger"
"github.com/flowexec/flow/pkg/store"
"github.com/flowexec/flow/types/executable"
)
func main() {
cfg, err := filesystem.LoadConfig()
if err != nil {
panic(fmt.Errorf("user config load error: %w", err))
}
archiveDir, archiveID := initLogArchive()
loggerOpts := logger.InitOptions{
StdOut: io.Stdout,
LogMode: cfg.DefaultLogMode,
Theme: logger.Theme(cfg.Theme.String()),
ArchiveDirectory: archiveDir,
ArchiveID: archiveID,
}
logger.Init(loggerOpts)
defer func() {
if err := logger.Log().Flush(); err != nil {
if errors.Is(err, os.ErrClosed) {
return
}
panic(err)
}
}()
initStore()
bkgCtx, cancelFunc := stdCtx.WithCancel(stdCtx.Background())
ctx := context.NewContext(bkgCtx, cancelFunc, context.WithStdIn(io.Stdin), context.WithStdOut(io.Stdout))
ctx.LogArchiveID = archiveID
defer ctx.Finalize()
if ctx == nil {
panic("failed to initialize context")
}
rootCmd := cli.BuildRootCommand(ctx)
cli.RegisterAllCommands(ctx, rootCmd)
if err := cmd.Execute(ctx, rootCmd); err != nil {
logger.Log().FatalErr(err)
}
}
func initLogArchive() (dir, id string) {
if args := os.Args; len(args) > 1 && slices.Contains(executable.ValidVerbs(), executable.Verb(args[1])) {
dir = filesystem.LogsDir()
id = uuid.New().String()
}
return
}
func initStore() {
if err := store.MigrateProcessBuckets(""); err != nil {
logger.Log().Debug("process bucket migration skipped or failed", "err", err)
}
}