template

package
v0.0.0-...-88bc37c Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2018 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ShowCmd = &cobra.Command{
	Use:   "show [Resource Template Path] [template options]",
	Short: "Show resource template details",
	Long:  "Show resource template details",
	Example: `
	% openvdc template show centos/7/lxc
	% openvdc template show ./templates/centos/7/null.json
	% openvdc template show https://raw.githubusercontent.com/axsh/openvdc/master/templates/centos/7/lxc.json
	` + util.ExampleMergeTemplateOptions("openvdc template show"),
	DisableFlagParsing: true,
	PreRunE:            util.PreRunHelpFlagCheckAndQuit,
	RunE: func(cmd *cobra.Command, args []string) error {
		if len(args) < 1 {
			return pflag.ErrHelp
		}
		templateSlug := args[0]
		rt, err := util.FetchTemplate(templateSlug)
		if err != nil {
			log.Fatal(err)
		}

		merged := rt.Template.Template
		if len(args) > 1 {
			merged = util.MergeTemplateParams(rt, args[1:])
		}

		fmt_type, err := cmd.Flags().GetString("format")
		switch fmt_type {
		case "json":
			if err := (&jsonpb.Marshaler{Indent: "  "}).Marshal(cmd.OutOrStdout(), merged.(proto.Message)); err != nil {
				log.WithError(err).Fatal("Faild to format to pretty JSON.")
			}
		case "protobuf":

			m := &proto.TextMarshaler{Compact: false}
			return m.Marshal(cmd.OutOrStdout(), merged.(proto.Message))
		default:
			log.Fatalf("Unknown format: %s", fmt_type)
		}
		return nil
	},
}
View Source
var ValidateCmd = &cobra.Command{
	Use:     "validate [Resource Template Path] [template options]",
	Aliases: []string{"test"},
	Short:   "Validate resource template",
	Long:    "Validate resource template",
	Example: `
	% openvdc template validate centos/7/lxc
	% openvdc template validate ./templates/centos/7/null.json
	% openvdc template validate https://raw.githubusercontent.com/axsh/openvdc/master/templates/centos/7/lxc.json
	` + util.ExampleMergeTemplateOptions("openvdc template validate"),
	DisableFlagParsing: true,
	PreRunE:            util.PreRunHelpFlagCheckAndQuit,
	RunE: func(cmd *cobra.Command, args []string) error {
		if len(args) < 1 {
			return pflag.ErrHelp
		}
		templateSlug := args[0]

		finder, err := util.TemplateFinder(templateSlug)
		if err != nil {
			log.WithError(err).Fatal("Failed util.TemplateFinder")
		}
		buf, err := finder.LoadRaw(templateSlug)
		if err != nil {
			log.WithError(err).Fatal("Failed finder.LoadRaw")
		}
		if err, ok := registry.ValidateTemplate(buf).(*registry.ErrInvalidTemplate); ok && err != nil {
			log.Fatal(err.Errors)
		}

		if len(args) > 1 {
			rt, err := util.FetchTemplate(templateSlug)
			if err != nil {
				log.WithError(err).Fatal("util.FetchTemplate")
			}
			util.MergeTemplateParams(rt, args[1:])
		}
		return nil
	},
}

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