cmd

package
Version: v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2018 License: CC0-1.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Validate = cli.Command{
	Name:  "validate",
	Usage: "validate files against OSCAL XML and JSON schemas",
	Description: `Validate OSCAL-formatted XML files against a specific XML schema (.xsd)
	 or OSCAL-formatted JSON files against a specific JSON schema`,
	ArgsUsage: "[files...]",
	Flags: []cli.Flag{
		cli.StringFlag{
			Name:        "schema, s",
			Usage:       "schema file to validate against",
			Destination: &schemaFile,
		},
	},
	Before: func(c *cli.Context) error {
		if c.NArg() < 1 {
			return cli.NewExitError("oscalkit validate requires at least one argument", 1)
		}

		if schemaFile == "" {
			return cli.NewExitError("missing schema file (-s) flag", 1)
		}

		for _, f := range c.Args() {
			if filepath.Ext(f) == ".xml" && filepath.Ext(schemaFile) != ".xsd" {
				return cli.NewExitError("Schema file should be .xsd", 1)
			}

			if filepath.Ext(f) == ".json" && filepath.Ext(schemaFile) != ".json" {
				return cli.NewExitError("Schema file should be .json", 1)
			}
		}

		return nil
	},
	Action: func(c *cli.Context) error {
		schemaValidator := validator.New(schemaFile)

		if err := schemaValidator.Validate(c.Args()...); err != nil {
			logrus.Error(err)
			return nil
		}

		logrus.Debug("Validation complete")

		return nil
	},
}

Validate ...

Functions

func Execute

func Execute() error

Execute ...

Types

This section is empty.

Source Files

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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