github.com/hazelops/ize@v1.1.12-0.20230915191306-97d7c0e48f11/internal/commands/validate.go (about)

     1  package commands
     2  
     3  import (
     4  	"fmt"
     5  	"github.com/hazelops/ize/internal/schema"
     6  	"github.com/pterm/pterm"
     7  	"github.com/spf13/cobra"
     8  	"github.com/spf13/viper"
     9  )
    10  
    11  func NewValidateCmd() *cobra.Command {
    12  	cmd := &cobra.Command{
    13  		Use:   "validate",
    14  		Short: "Validate configuration (only for test)",
    15  		RunE: func(cmd *cobra.Command, args []string) error {
    16  			cmd.SilenceUsage = true
    17  
    18  			err := schema.Validate(viper.AllSettings())
    19  			fmt.Println(viper.AllSettings())
    20  
    21  			if err != nil {
    22  				return err
    23  			}
    24  
    25  			pterm.Success.Println("Config structure, env vars and flags look valid. ")
    26  
    27  			return nil
    28  		},
    29  	}
    30  
    31  	return cmd
    32  }