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