示例#1
0
文件: main.go 项目: hhshih/dogo
func main() {
	runtime.GOMAXPROCS(runtime.NumCPU())

	var c string
	flag.StringVar(&c, "c", console.WorkingDir+"/dogo.json", "Usage: dogo -c=/path/to/dogo.json")
	flag.Parse()

	var dogo Dogo

	gopath := console.Getenv("GOPATH")
	c = strings.Replace(c, "{GOPATH}", gopath, -1)

	r := map[string]string{"{GOPATH}": gopath}
	err := config.NewConfig(c).Replace(r).Parse(&dogo)
	if err != nil {
		fmt.Printf("[dogo] Warning: no configuration file loaded.\n")
	} else {
		fmt.Printf("[dogo] Loaded configuration file:\n")
		fmt.Printf("       %s\n", c)
	}

	dogo.NewMonitor()

	l := len(dogo.Files)
	if l > 0 {
		fmt.Printf("[dogo] Ready. %d files to be monitored.\n\n", l)
		dogo.BuildAndRun()
		dogo.Monitor()
	} else {
		fmt.Printf("[dogo] Error: Did not find any files. Press any key to exit.\n\n")
		var a string
		fmt.Scanf("%s", &a)
	}
}
示例#2
0
//start new monitor
func (d *Dogo) NewMonitor() {
	//fmt.Printf("%#v\n", d.SourceDir)

	if d.WorkingDir == "" {
		//log.Fatalf("[dogo] dogo.json (BuildCmd) error. \n")
		d.WorkingDir = console.WorkingDir
	}
	if len(d.SourceDir) == 0 {
		//log.Fatalf("[dogo] dogo.json (SourceDir) error. \n")
		d.SourceDir = append(d.SourceDir, console.WorkingDir)
	}
	if d.SourceExt == "" {
		//log.Fatalf("[dogo] dogo.json (SourceExt) error. \n")
		d.SourceExt = ".go|.c|.cpp|.h"
	}
	if d.BuildCmd == "" {
		//log.Fatalf("[dogo] dogo.json (BuildCmd) error. \n")
		d.BuildCmd = "go build ."
	}
	if d.RunCmd == "" {
		//log.Fatalf("[dogo] dogo.json (RunCmd) error. \n")
		d.RunCmd = filepath.Base(console.WorkingDir)
		if runtime.GOOS == "windows" {
			d.RunCmd += ".exe"
		}
	}

	// Append the current directory to the PATH for compatible linux.
	console.Setenv("PATH", console.Getenv("PATH")+string(os.PathListSeparator)+d.WorkingDir)

	console.Chdir(d.WorkingDir)
	fmt.Printf("[dogo] Working Directory:\n")
	fmt.Printf("       %s\n", d.WorkingDir)

	fmt.Printf("[dogo] Monitoring Directories:\n")
	for _, dir := range d.SourceDir {
		fmt.Printf("       %s\n", dir)
	}

	fmt.Printf("[dogo] File extends:\n")
	fmt.Printf("       %s\n", d.SourceExt)

	fmt.Printf("[dogo] Build command:\n")
	fmt.Printf("       %s\n", d.BuildCmd)

	fmt.Printf("[dogo] Run command:\n")
	fmt.Printf("       %s\n", d.RunCmd)

	d.Files = make(map[string]time.Time)
	d.InitFiles()

	//FIXME: add console support.

	//FIXME: moniting directories: add file, delete file.

	//FIXME: Multi commands.
}
示例#3
0
文件: dogo.go 项目: vanishs/dogo
//start new monitor
func (d *Dogo) NewMonitor() {
	if d.WorkingDir == "" {
		d.WorkingDir = console.WorkingDir
	}
	if len(d.SourceDir) == 0 {
		d.SourceDir = append(d.SourceDir, console.WorkingDir)
	}
	if d.SourceExt == nil || len(d.SourceExt) == 0 {
		d.SourceExt = []string{".c", ".cpp", ".go", ".h"}
	}
	if d.BuildCmd == "" {
		d.BuildCmd = "go build ."
	}
	if d.RunCmd == "" {
		d.RunCmd = filepath.Base(console.WorkingDir)
		if runtime.GOOS == "windows" {
			d.RunCmd += ".exe"
		}
	}

	// Append the current directory to the PATH for compatible linux.
	console.Setenv("PATH", console.Getenv("PATH")+string(os.PathListSeparator)+d.WorkingDir)

	console.Chdir(d.WorkingDir)
	fmt.Printf("[dogo] Working Directory:\n")
	fmt.Printf("       %s\n", d.WorkingDir)

	fmt.Printf("[dogo] Monitoring Directories:\n")
	for _, dir := range d.SourceDir {
		fmt.Printf("       %s\n", dir)
	}

	fmt.Printf("[dogo] File extends:\n")
	fmt.Printf("       %s\n", d.SourceExt)

	fmt.Printf("[dogo] Build command:\n")
	fmt.Printf("       %s\n", d.BuildCmd)

	fmt.Printf("[dogo] Run command:\n")
	fmt.Printf("       %s\n", d.RunCmd)

	d.Files = make(map[string]time.Time)
	d.InitFiles()

	//TODO: add console support.
	//TODO: Multi commands.
}