Esempio n. 1
0
func TestFixPath(t *testing.T) {
	if string(os.PathSeparator) == "/" {
		if helpers.FixPath("/a/b/c") != "/a/b/c" {
			t.Error("")
		}
	} else {
		if helpers.FixPath("/a/b/c") != "\\a\\b\\c" {
			t.Error("")
		}
	}
}
Esempio n. 2
0
func (resource *Resource) templatize(files map[string]string) error {

	// nb: generatorsTemplatesPath
	for templateType, file := range files {
		var buffer bytes.Buffer

		// preventing overwriting
		if _, err := os.Stat(file); err == nil {
			fmt.Println(yellow, "  exists:", reset, file)
			continue
		}

		// reading and processing template
		templateContents, err := ioutil.ReadFile(
			helpers.FixPath(
				generatorsTemplatesPath +
					string(os.PathSeparator) +
					templatesPaths[templateType],
			),
		)

		tmpl, err := template.New("generator").Parse(string(templateContents))
		if err != nil {
			log.Fatal(err)
		}
		tmpl.Execute(&buffer, resource)

		// writing template in appropriate folder
		err = ioutil.WriteFile(helpers.FixPath(file), buffer.Bytes(), 0644)
		if err != nil {
			log.Fatal(err)
		}

		fmt.Println(green, "  create:", reset, file)
	}
	return nil
}
Esempio n. 3
0
File: cli.go Progetto: kelyar/clio
	tcpIPCPort = 31000

	red    = "\x1b[0;31m"
	green  = "\x1b[0;32m"
	yellow = "\x1b[0;33m"
	reset  = "\x1b[0m"
)

var (
	slash = string(os.PathSeparator)

	GOPATH     = os.Getenv("GOPATH")
	GOPATH_SRC = GOPATH + slash + "src" + slash

	templatesRoot            = "src/github.com/cliohq/clio/templates"
	applicationTemplatesPath = helpers.FixPath(templatesRoot + "/application")
	generatorsTemplatesPath  = helpers.FixPath(helpers.FixPath(GOPATH + "/" + templatesRoot + "/generators"))
)

/**
 *  Dispatching command-line arguments to a separate
 *  command execution
 */
func Route() {
	if len(os.Args) > 1 {

		switch os.Args[1] {

		case "help":
			Help()