-
Notifications
You must be signed in to change notification settings - Fork 4
/
stencil.go
143 lines (119 loc) 路 3.99 KB
/
stencil.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
// Copyright 2024 Outreach Corporation. All Rights Reserved.
// Description: This file is the entrypoint for the stencil CLI
// command for stencil.
// Managed: true
package main
import (
"context"
"os"
"path/filepath"
oapp "github.com/getoutreach/gobox/pkg/app"
"github.com/getoutreach/gobox/pkg/box"
"github.com/getoutreach/gobox/pkg/cfg"
gcli "github.com/getoutreach/gobox/pkg/cli"
"github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"
// Place any extra imports for your startup code here
// <<Stencil::Block(imports)>>
"github.com/getoutreach/stencil/internal/cmd/stencil"
"github.com/getoutreach/stencil/pkg/configuration"
"github.com/pkg/errors"
// <</Stencil::Block>>
)
// HoneycombTracingKey gets set by the Makefile at compile-time which is pulled
// down by devconfig.sh.
var HoneycombTracingKey = "NOTSET" //nolint:gochecknoglobals // Why: We can't compile in things as a const.
// TeleforkAPIKey gets set by the Makefile at compile-time which is pulled
// down by devconfig.sh.
var TeleforkAPIKey = "NOTSET" //nolint:gochecknoglobals // Why: We can't compile in things as a const.
// <<Stencil::Block(honeycombDataset)>>
// HoneycombDataset is the dataset to use when talking to Honeycomb
const HoneycombDataset = "dev-tooling-team"
// <</Stencil::Block>>
// <<Stencil::Block(global)>>
// <</Stencil::Block>>
// main is the entrypoint for the stencil CLI.
func main() {
ctx, cancel := context.WithCancel(context.Background())
log := logrus.New()
// <<Stencil::Block(init)>>
// <</Stencil::Block>>
app := cli.App{
Version: oapp.Version,
Name: "stencil",
// <<Stencil::Block(app)>>
Description: "a smart templating engine for service development",
Action: func(c *cli.Context) error {
log.Infof("stencil %s", oapp.Version)
if c.Bool("debug") {
log.SetLevel(logrus.DebugLevel)
log.Debug("Debug logging enabled")
}
serviceManifest, err := configuration.NewDefaultServiceManifest()
if err != nil {
return errors.Wrap(err, "failed to parse service.yaml")
}
homeDir, err := os.UserHomeDir()
if err != nil {
return errors.Wrap(err, "failed to get user's home directory")
}
// If we have a box config, ensure it's up to date. In the future this may
// become a requirement to run stencil.
if _, err := os.Stat(filepath.Join(homeDir, box.BoxConfigPath, box.BoxConfigFile)); err == nil {
if _, err := box.EnsureBoxWithOptions(ctx, box.WithLogger(log)); err != nil {
return errors.Wrap(err, "failed to load box config")
}
}
cmd := stencil.NewCommand(log, serviceManifest, c.Bool("dry-run"),
c.Bool("frozen-lockfile"), c.Bool("use-prerelease"), c.Bool("allow-major-version-upgrades"))
return errors.Wrap(cmd.Run(ctx), "run codegen")
},
// <</Stencil::Block>>
}
app.Flags = []cli.Flag{
// <<Stencil::Block(flags)>>
&cli.BoolFlag{
Name: "dry-run",
Aliases: []string{"dryrun"},
Usage: "Don't write files to disk",
},
&cli.BoolFlag{
Name: "frozen-lockfile",
Usage: "Use versions from the lockfile instead of the latest",
},
&cli.BoolFlag{
Name: "use-prerelease",
Usage: "Use prerelease versions of stencil modules",
},
&cli.BoolFlag{
Name: "allow-major-version-upgrades",
Usage: "Allow major version upgrades without confirmation",
},
&cli.BoolFlag{
Name: "debug",
Usage: "Enables debug logging for version resolution, template render, and other useful information",
Aliases: []string{"d"},
},
// <</Stencil::Block>>
}
app.Commands = []*cli.Command{
// <<Stencil::Block(commands)>>
NewDescribeCmd(),
NewCreateCommand(),
NewDocsCommand(),
NewConfigureCommand(),
// <</Stencil::Block>>
}
// <<Stencil::Block(postApp)>>
// <</Stencil::Block>>
// Insert global flags, tracing, updating and start the application.
gcli.Run(ctx, cancel, &app, &gcli.Config{
Logger: log,
Telemetry: gcli.TelemetryConfig{
Otel: gcli.TelemetryOtelConfig{
Dataset: HoneycombDataset,
HoneycombAPIKey: cfg.SecretData(HoneycombTracingKey),
},
},
})
}