示例#1
0
func buildMain(src string) string {
	mustBeMain(src)

	exeFile := "godobin-" + godo.Version
	if isWindows {
		exeFile += ".exe"
	}

	dir := filepath.Dir(src)
	exe := filepath.Join(dir, exeFile)
	reasonFormat := "Godofile changed. Rebuilding %s...\n"

	argm := minimist.Parse()
	rebuild := argm.ZeroBool("rebuild")
	if rebuild {
		os.Remove(exe)
	}

	// see if last run exists .godoinfo
	fiExe, err := os.Stat(exe)
	build := os.IsNotExist(err)
	if build {
		reasonFormat = "Building %s...\n"
	}

	fiGodofile, err := os.Stat(src)
	if os.IsNotExist(err) {
		log.Fatalln(err)
		os.Exit(1)
	}
	build = build || fiExe.ModTime().Before(fiGodofile.ModTime())

	if build {
		util.Debug("godo", reasonFormat, exe)

		err := godo.Run("go build -a -o "+exeFile, godo.In{dir})
		if err != nil {
			panic(err)
		}
	}

	if rebuild {
		util.Info("godo", "ok")
		os.Exit(0)
	}

	return exe
}
示例#2
0
func main() {
	argm := minimist.Parse()
	fmt.Printf("%q\n", os.Args)

	// cmd --help || cmd --h || cmd -?
	if argm.MayBool(false, "help", "h", "?") {
		fmt.Println(usage)
	}

	// cmd -v || cmd --version
	if argm.AsBool("v", "version") {
		fmt.Println("1.0")
	}

	// cmd foo -- ...
	// argm.SubCommand("foo", func(a *ArgMap) {
	// })

	// argm.SubExec("talk", "echo")
}
示例#3
0
func godo(tasksFunc func(*Project), argv []string) {
	if argv == nil {
		argm = minimist.Parse()
	} else {
		argm = minimist.ParseArgv(argv)
	}

	help = argm.ZeroBool("help", "h", "?")
	verbose = argm.ZeroBool("verbose", "v")
	version = argm.ZeroBool("version", "V")
	watching = argm.ZeroBool("watch", "w")
	deprecatedWarnings = argm.ZeroBool("D")
	contextArgm = minimist.ParseArgv(argm.Unparsed())

	project := NewProject(tasksFunc)

	if help {
		Usage(project.usage())
		os.Exit(0)
	}

	if version {
		fmt.Printf("godo %s\n", Version)
		os.Exit(0)
	}

	// Run each task including their dependencies.
	args := []string{}
	for _, v := range argm.Leftover() {
		args = append(args, fmt.Sprintf("%v", v))
	}

	if len(args) == 0 {
		if project.Tasks["default"] != nil {
			args = append(args, "default")
		} else {
			Usage(project.usage())
			os.Exit(0)
		}
	}

	// quick fix to make cascading watch work on default task
	if len(args) == 1 && args[0] == "default" {
		args = project.Tasks["default"].Dependencies
	}

	for _, name := range args {
		err := project.Run(name)
		if err != nil {
			util.Error("ERR", "%s\n", err.Error())
			os.Exit(1)
		}
	}

	if watching {
		if project.Watch(args, true) {
			waitgroup.Add(1)
			waitExit = true
		} else {
			fmt.Println("Nothing to watch. Use W{} or Watch{} to specify glob patterns")
			os.Exit(0)
		}
	}

	if waitExit {
		waitgroup.Wait()
	}
}