mirror of
https://github.com/holos-run/holos.git
synced 2026-03-21 01:35:02 +00:00
Make the log messages clear and readable, for example:
holos render --log-format=json --log-level=debug \
--cluster-name core2 ./docs/examples/platforms/reference/projects/secrets/components/namespaces/ \
2> >(jq -r '"\(.source.file):\(.source.line)\t" + .msg')
The msg field is intended to have an imperative verb, ideally in the
past tense, followed by an actionable noun. Past tense indicates
success where as the "could not foo: "+err error form indicates an
attempt to do something that failed.
config.go:91 finalized config from flags
builder.go:115 cue export --out yaml ./platforms/reference/projects/secrets/components/namespaces
builder.go:85 wrote deploy/clusters/core2/components/prod-secrets-namespaces/prod-secrets-namespaces.gen.yaml
render.go:30 rendered prod-secrets-namespaces
47 lines
1.4 KiB
Go
47 lines
1.4 KiB
Go
package cli
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/holos-run/holos/pkg/config"
|
|
"github.com/holos-run/holos/pkg/internal/builder"
|
|
"github.com/holos-run/holos/pkg/logger"
|
|
"github.com/holos-run/holos/pkg/wrapper"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
func makeRenderRunFunc(cfg *config.Config) runFunc {
|
|
return func(cmd *cobra.Command, args []string) error {
|
|
if cfg.ClusterName() == "" {
|
|
return wrapper.Wrap(fmt.Errorf("missing cluster name"))
|
|
}
|
|
|
|
ctx := cmd.Context()
|
|
log := logger.FromContext(ctx)
|
|
build := builder.New(builder.Entrypoints(args))
|
|
results, err := build.Run(cmd.Context())
|
|
if err != nil {
|
|
return wrapper.Wrap(err)
|
|
}
|
|
for _, result := range results {
|
|
path := result.Filename(cfg.WriteTo(), cfg.ClusterName())
|
|
if err := result.Save(ctx, path); err != nil {
|
|
return wrapper.Wrap(err)
|
|
}
|
|
log.InfoContext(ctx, "rendered "+result.Name(), "status", "ok", "action", "save", "path", path, "name", result.Name())
|
|
}
|
|
return nil
|
|
}
|
|
}
|
|
|
|
// newRenderCmd returns the render subcommand for the root command
|
|
func newRenderCmd(cfg *config.Config) *cobra.Command {
|
|
cmd := newCmd("render [directory...]")
|
|
cmd.Args = cobra.MinimumNArgs(1)
|
|
cmd.Short = "write kubernetes api objects to the filesystem"
|
|
cmd.Flags().SortFlags = false
|
|
cmd.Flags().AddGoFlagSet(cfg.WriteFlagSet())
|
|
cmd.Flags().AddGoFlagSet(cfg.ClusterFlagSet())
|
|
cmd.RunE = makeRenderRunFunc(cfg)
|
|
return cmd
|
|
}
|