validate

package
v0.6.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 9, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Command = &cobra.Command{
	Use:   "validate",
	Short: "Validate .env file",
	RunE: func(cmd *cobra.Command, args []string) error {
		env, _, err := shared.Setup(cmd.Flags())
		if err != nil {
			return err
		}

		res := validation.Validate(env)
		if len(res) == 0 {
			tui.Theme.Success.StderrPrinter().Box("No validation errors found")

			return nil
		}

		stderr := tui.Theme.Danger.StderrPrinter()
		stderr.Box(fmt.Sprintf("%d validation errors found", len(res)))
		stderr.Println()

		for _, errIsh := range res {
			validation.Explain(env, errIsh)
		}

		env, err = pkg.Load(cmd.Flag("file").Value.String())
		if err != nil {
			return fmt.Errorf("failed to reload .env file: %w", err)
		}

		newRes := validation.Validate(env)
		if len(newRes) == 0 {
			tui.Theme.Success.StderrPrinter().Println("All validation errors fixed")

			return nil
		}

		diff := len(res) - len(newRes)
		if diff > 0 {
			tui.Theme.Warning.StderrPrinter().Box(
				fmt.Sprintf("%d validation errors left", len(newRes)),
				tui.Theme.Success.StderrPrinter().Sprintf("%d validation errors was fixed", diff),
			)
		}

		return errors.New("Validation failed")
	},
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL