Sfoglia il codice sorgente

support setting the project type manually.

Lucas Stadler 11 anni fa
parent
commit
e87460f71b
2 ha cambiato i file con 23 aggiunte e 1 eliminazioni
  1. 9 0
      go/detect/detect.go
  2. 14 1
      go/qst.go

+ 9 - 0
go/detect/detect.go

@ -63,6 +63,15 @@ func DetectAll(file string) []*Project {
63 63
	return projects
64 64
}
65 65
66
func GetById(id string) *Project {
67
	for _, project := range ProjectTypes {
68
		if project.Id == id {
69
			return project
70
		}
71
	}
72
	return nil
73
}
74
66 75
func matchingFileOrDir(file string, pattern string) bool {
67 76
	if fileutil.IsFile(file) {
68 77
		_, f := path.Split(file)

+ 14 - 1
go/qst.go

@ -32,6 +32,7 @@ qst hello.go - compiles & runs hello.go
32 32
var delay = flag.Duration("delay", 1*time.Second, "time to wait until restart")
33 33
var autoRestart = flag.Bool("autorestart", true, "automatically restart after command exists")
34 34
var command = flag.String("command", "", "command to run ({file} will be substituted)")
35
var projectType = flag.String("type", "", "project type to use (autodetected if not present)")
35 36
36 37
func main() {
37 38
	log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile)
@ -56,10 +57,18 @@ func main() {
56 57
	// }
57 58
58 59
	var cmd string
59
	if command != nil && strings.TrimSpace(*command) != "" {
60
	if !flagEmpty(command) {
60 61
		cmd = *command
61 62
	} else {
62 63
		project, err := detect.Detect(file)
64
		if !flagEmpty(projectType) {
65
			project = detect.GetById(*projectType)
66
			if project == nil {
67
				log.Fatalf("unknown type: `%s'", *projectType)
68
			} else if !project.Detect(file) {
69
				log.Fatalf("%s doesn't match type %s!", file, *projectType)
70
			}
71
		}
63 72
		if err != nil {
64 73
			log.Fatal("error: ", err)
65 74
		}
@ -87,6 +96,10 @@ func main() {
87 96
	runner.Stop()
88 97
}
89 98
99
func flagEmpty(stringFlag *string) bool {
100
	return stringFlag == nil || strings.TrimSpace(*stringFlag) == ""
101
}
102
90 103
func runCmd(file string, runner *Runner) {
91 104
	runner.Start()
92 105
	lastMtime := time.Now()