Beispiel #1
0
func create(dir string) (err error) {
	var template = templateLib
	if argPkgIsCommand.Get() {
		template = templateCmd
	}
	return scaffold.Run(dir, template, strings.NewReader(fmt.Sprintf(`{"Name": %#v}`, argPkgName.Get())), nil, false)
}
Beispiel #2
0
func main() {

	var (
		err         error
		dir         string
		file        string
		templateRaw []byte
	)

steps:
	for jump := 1; err == nil; jump++ {
		switch jump - 1 {
		default:
			break steps
		case 0:
			err = cfg.Run()
		case 1:
			dir, err = filepath.Abs(dirArg.Get())
		case 2:
			file, err = findFile()
		case 3:
			println("found ", file)
			templateRaw, err = ioutil.ReadFile(file)
		case 4:
			head, template := scaffold.SplitTemplate(string(templateRaw))
			switch cfg.ActiveCommand() {
			case nil:
				err = scaffold.Run(dir, template, os.Stdin, os.Stdout, false)
			case testCmd:
				err = scaffold.Run(dir, template, os.Stdin, os.Stdout, true)
			case headCmd:
				fmt.Fprintln(os.Stdout, head)
			}
		}
	}

	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		fmt.Fprintln(os.Stdout, " -> run 'scaffold help' to get more help")
		os.Exit(1)
	}
}