1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2024-12-31 01:53:50 +02:00
goreleaser/cmd/check.go
Carlos Alexandro Becker fe7e2123bd
feat: replacing the log library (#3139)
* feat: replacing logs

Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>

* fix: tests et al

Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>

* feat: update termenv/lipgloss

Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>

* wip: output

Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>

* fix: pin dep

Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>

* fix: update

Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>

* fix: tests

Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>

* fix: tests

Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>

* fix: deps

Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>

* fix: dep

Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>
2022-06-21 21:11:15 -03:00

70 lines
1.7 KiB
Go

package cmd
import (
"fmt"
"io"
"github.com/caarlos0/ctrlc"
"github.com/caarlos0/log"
"github.com/goreleaser/goreleaser/internal/pipe/defaults"
"github.com/goreleaser/goreleaser/pkg/context"
"github.com/spf13/cobra"
)
type checkCmd struct {
cmd *cobra.Command
config string
quiet bool
deprecated bool
}
func newCheckCmd() *checkCmd {
root := &checkCmd{}
cmd := &cobra.Command{
Use: "check",
Aliases: []string{"c"},
Short: "Checks if configuration is valid",
SilenceUsage: true,
SilenceErrors: true,
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
if root.quiet {
log.Log = log.New(io.Discard)
}
cfg, err := loadConfig(root.config)
if err != nil {
return err
}
ctx := context.New(cfg)
ctx.Deprecated = root.deprecated
if err := ctrlc.Default.Run(ctx, func() error {
log.Info(boldStyle.Render("checking config..."))
return defaults.Pipe{}.Run(ctx)
}); err != nil {
log.WithError(err).Error(boldStyle.Render("config is invalid"))
return fmt.Errorf("invalid config: %w", err)
}
if ctx.Deprecated {
return wrapErrorWithCode(
fmt.Errorf("config is valid, but uses deprecated properties, check logs above for details"),
2,
"",
)
}
log.Infof(boldStyle.Render("config is valid"))
return nil
},
}
cmd.Flags().StringVarP(&root.config, "config", "f", "", "Configuration file to check")
cmd.Flags().BoolVarP(&root.quiet, "quiet", "q", false, "Quiet mode: no output")
cmd.Flags().BoolVar(&root.deprecated, "deprecated", false, "Force print the deprecation message - tests only")
_ = cmd.Flags().MarkHidden("deprecated")
root.cmd = cmd
return root
}