Przeglądaj źródła

allow passing the command directly.

Lucas Stadler 11 lat temu
rodzic
commit
5ad45c1200
1 zmienionych plików z 13 dodań i 5 usunięć
  1. 13 5
      go/qst.go

+ 13 - 5
go/qst.go

@ -38,6 +38,7 @@ var mappings = map[string]func(string) string{
38 38
39 39
var delay = flag.Duration("delay", 1*time.Second, "time to wait until restart")
40 40
var autoRestart = flag.Bool("autorestart", true, "restart after command exists")
41
var command = flag.String("command", "", "command to run ({file} will be substituted)")
41 42
42 43
func main() {
43 44
	log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile)
@ -61,13 +62,20 @@ func main() {
61 62
		os.Exit(1)
62 63
	}
63 64
64
	ext := path.Ext(file)
65
	fn, found := mappings[ext]
66
	if !found {
67
		log.Fatalf("error: no mapping found for `%s'", file)
65
	var cmd string
66
	if command != nil && strings.TrimSpace(*command) != "" {
67
		cmd = strings.Replace(*command, "{file}", file, -1)
68
	} else {
69
		ext := path.Ext(file)
70
		fn, found := mappings[ext]
71
		if !found {
72
			log.Fatalf("error: no mapping found for `%s'", file)
73
		}
74
		cmd = fn(file)
68 75
	}
76
	log.Printf("command to run: `%s'", cmd)
69 77
70
	runner := &Runner{nil, fn(file), false, *autoRestart}
78
	runner := &Runner{nil, cmd, false, *autoRestart}
71 79
	go runCmd(file, runner)
72 80
73 81
	c := make(chan os.Signal, 1)