Beispiel #1
0
func loadTemplate(args []string) *expander.Template {
	var template *expander.Template
	var err error
	if len(args) < 2 {
		fmt.Fprintln(os.Stderr, "No template name or configuration(s) supplied")
		usage()
	}

	if len(args) < 3 {
		if t := getRegistryType(args[1]); t != nil {
			template = buildTemplateFromType(*t)
		} else {
			template, err = expander.NewTemplateFromRootTemplate(args[1])
		}
	} else {
		template, err = expander.NewTemplateFromFileNames(args[1], args[2:])
	}

	if err != nil {
		log.Fatalf("cannot create configuration from supplied arguments: %s\n", err)
	}

	// Override name if set from flags.
	if *deployment_name != "" {
		template.Name = *deployment_name
	}

	return template
}
func loadTemplate(name string) *expander.Template {
	args := flag.Args()
	if len(args) < 1 {
		usage()
		os.Exit(1)
	}

	var template *expander.Template
	var err error
	if len(args) == 1 {
		if t := getRegistryType(args[0]); t != nil {
			template = buildTemplateFromType(name, *t)
		} else {
			template, err = expander.NewTemplateFromRootTemplate(args[0])
		}
	} else {
		template, err = expander.NewTemplateFromFileNames(args[0], args[1:])
	}
	if err != nil {
		log.Fatalf("cannot create template from supplied file names: %s\n", err)
	}

	if name != "" {
		template.Name = name
	}

	return template
}
Beispiel #3
0
func loadTemplate(args []string) *common.Template {
	var template *common.Template
	var err error
	if len(args) < 2 {
		fmt.Fprintln(os.Stderr, "No template name or configuration(s) supplied")
		usage()
	}

	if *stdin {
		if len(args) < 2 {
			usage()
		}

		input, err := ioutil.ReadAll(os.Stdin)
		if err != nil {
			panic(err)
		}

		r := bytes.NewReader(input)
		template, err = expander.NewTemplateFromArchive(args[1], r, args[2:])
		if err != nil {
			if err != tar.ErrHeader {
				panic(err)
			}

			r := bytes.NewReader(input)
			template, err = expander.NewTemplateFromReader(args[1], r, args[2:])
			if err != nil {
				panic(fmt.Errorf("cannot create configuration from supplied arguments: %s\n", err))
			}
		}
	} else {
		// See if the first argument is a local file. It could either be a type, or it could be a configuration. If
		// it's a local file, it's configuration.
		if _, err := os.Stat(args[1]); err == nil {
			if len(args) > 2 {
				template, err = expander.NewTemplateFromFileNames(args[1], args[2:])
			} else {
				template, err = expander.NewTemplateFromRootTemplate(args[1])
			}
		} else {
			template = buildTemplateFromType(args[1])
		}

		if err != nil {
			panic(fmt.Errorf("cannot create configuration from supplied arguments: %s\n", err))
		}
	}

	// Override name if set from flags.
	if *deployment_name != "" {
		template.Name = *deployment_name
	}

	return template
}
Beispiel #4
0
func loadTemplate(args []string) *common.Template {
	var template *common.Template
	var err error
	if len(args) < 2 {
		fmt.Fprintln(os.Stderr, "No template name or configuration(s) supplied")
		usage()
	}

	if *stdin {
		if len(args) < 2 {
			usage()
		}

		input, err := ioutil.ReadAll(os.Stdin)
		if err != nil {
			panic(err)
		}

		r := bytes.NewReader(input)
		template, err = expander.NewTemplateFromArchive(args[1], r, args[2:])
		if err != nil {
			if err != tar.ErrHeader {
				panic(err)
			}

			r := bytes.NewReader(input)
			template, err = expander.NewTemplateFromReader(args[1], r, args[2:])
			if err != nil {
				panic(fmt.Errorf("cannot create configuration from supplied arguments: %s\n", err))
			}
		}
	} else {
		if len(args) < 3 {
			if t := getRegistryType(args[1]); t != nil {
				template = buildTemplateFromType(*t)
			} else {
				template, err = expander.NewTemplateFromRootTemplate(args[1])
			}
		} else {
			template, err = expander.NewTemplateFromFileNames(args[1], args[2:])
		}

		if err != nil {
			panic(fmt.Errorf("cannot create configuration from supplied arguments: %s\n", err))
		}
	}

	// Override name if set from flags.
	if *deployment_name != "" {
		template.Name = *deployment_name
	}

	return template
}
Beispiel #5
0
func loadTemplate(args []string) *expander.Template {
	var template *expander.Template
	var err error
	if len(args) < 2 {
		fmt.Fprintln(os.Stderr, "No type name or template file(s) supplied")
		usage()
	}

	if len(args) < 3 {
		if t := getRegistryType(args[1]); t != nil {
			template = buildTemplateFromType(args[1], *t)
		} else {
			template, err = expander.NewTemplateFromRootTemplate(args[1])
		}
	} else {
		template, err = expander.NewTemplateFromFileNames(args[1], args[2:])
	}

	if err != nil {
		log.Fatalf("cannot create template from supplied arguments: %s\n", err)
	}

	return template
}