cmd

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 23, 2019 License: BSD-3-Clause Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// RootCmd is the command to run for kubernetes json schema validation.
	RootCmd = &cobra.Command{
		Use:   "kubeschema <file> [file...]",
		Short: "Validate kubernetes json schema for helm chart YAML file",
		Long:  `Validate kubernetes json schema for helm chart YAML file`,
		Run: func(cmd *cobra.Command, args []string) {
			if version {
				printVersion()
				os.Exit(0)
			}
			success, windowsStdinIssue := true, false
			stat, err := os.Stdin.Stat()
			if err != nil {
				if runtime.GOOS != "windows" {
					logger.Error(red(err))
					os.Exit(1)
				} else {
					windowsStdinIssue = true
				}
			}

			if (len(args) < 1 || args[0] == "-") && !windowsStdinIssue && ((stat.Mode() & os.ModeCharDevice) == 0) {
				var buffer bytes.Buffer
				scanner := bufio.NewScanner(os.Stdin)
				for scanner.Scan() {
					buffer.WriteString(scanner.Text() + "\n")
				}
				results, err := validator.Validate(buffer.Bytes(), viper.GetString("filename"))
				if err != nil {
					logger.Error(red(err))
					os.Exit(1)
				}
				success = logResults(results, success)
			} else {
				if len(args) < 1 {
					logger.Error(red("Missing filename in argument"))
					os.Exit(1)
				}
				for _, fileName := range args {
					filePath, _ := filepath.Abs(fileName)
					fileContents, err := ioutil.ReadFile(filePath)
					if err != nil {
						logger.Error(red("Failed to open file ", fileName))
						os.Exit(1)
					}
					results, err := validator.Validate(fileContents, fileName)
					if err != nil {
						logger.Error(red(err))
						os.Exit(1)
					}
					success = logResults(results, success)
				}
			}
			if !success {
				os.Exit(1)
			}
		},
	}
)

Functions

func Execute

func Execute()

Execute adds command flags to the root command and execute it.

Types

This section is empty.

Jump to

Keyboard shortcuts

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