-
Notifications
You must be signed in to change notification settings - Fork 8
/
generator.go
77 lines (59 loc) · 1.59 KB
/
generator.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
package mify
import (
"context"
"fmt"
"github.com/mify-io/mify/internal/mify/status"
"github.com/mify-io/mify/internal/mify/util/docker"
"github.com/mify-io/mify/pkg/generator"
"github.com/mify-io/mify/pkg/generator/core"
"github.com/mify-io/mify/pkg/workspace"
)
func ServiceGenerateMany(ctx *CliContext, basePath string, names []string, migrate bool, force bool) error {
descr, err := workspace.InitDescription(basePath)
if err != nil {
return err
}
if len(names) == 0 {
names = descr.GetApiServices()
names = append(names, workspace.DevRunnerName)
}
for _, name := range names {
if err := ServiceGenerate(ctx, basePath, name, migrate, force); err != nil {
return fmt.Errorf("service '%s' generation failed: %w", name, err)
}
}
return nil
}
func ServiceGenerate(ctx *CliContext, basePath string, name string, migrate bool, force bool) error {
descr, err := workspace.InitDescription(basePath)
if err != nil {
return err
}
genPipeline := generator.BuildServicePipeline()
pg := status.NewGeneratorCliProgress(genPipeline)
outChan := make(chan core.StepExecResult)
go genPipeline.Execute(ctx.Ctx, name, descr, migrate, force, ctx.MifyVersion, outChan)
for {
stepResult := <-outChan
pg.ReportStep(&stepResult)
if stepResult.Error != nil {
return stepResult.Error
}
if stepResult.SeqNo == genPipeline.Size()-1 {
break
}
}
pg.Wait()
return nil
}
func Cleanup(appContext *CliContext) error {
err := docker.Cleanup(context.Background())
if err != nil {
return err
}
err = UpdateConfig(appContext.Config)
if err != nil {
return err
}
return nil
}