示例#1
0
func xinit() {
	g.Desc("Hello's Description")
	g.Task("hello", func(self *g.TaskInfo) {
		fmt.Printf("Hello!\n")
	})

	g.Task("task2", func(self *g.TaskInfo) {
		fmt.Printf("task2\n")
		fmt.Printf("ls=%s\n", System("ls", "-ltrh"))
		fmt.Printf("sleep=%s\n", System("sleep", "4"))
		if !f.Exists("output-file.txt") {
			fmt.Printf("")
		}
	})
	g.Depends("hello")

	g.Task("task3", func(self *g.TaskInfo) {
		fmt.Printf("task3\n")
		fmt.Printf("sleep=%s\n", System("sleep", "4"))
	})

	g.Task("task3.3", func(self *g.TaskInfo) {
		fmt.Printf("task3.3\n")
		fmt.Printf("sleep=%s\n", System("sleep", "4"))
	})

	g.Desc("Task to execute, with 3 deps")
	g.Task("task4", func(self *g.TaskInfo) {
		fmt.Printf("task4 self=%q\n", self)
	})
	g.Depends("task2", "task3", "task3.3")
}
示例#2
0
func make_all_tasks() {
	// vim: ft=go

	g.Desc("not in a namespace")
	g.Task("hello", func(self *g.TaskInfo) {
		fmt.Printf("in task: %s\n", self.Name)
	})

	g.Namespace("main", func() {
		g.Desc("This is a test task")
		g.Task("hello", func(self *g.TaskInfo) {
			fmt.Printf("Hello! from: %s\n", self.Name)
		})
		g.Depends("hello")

		g.Namespace("two", func() {
			g.Desc("a task with arguments")
			g.Task("hasargs[a,b,c]", func(self *g.TaskInfo) {
				fmt.Printf("%s, self.Args: %q\n", self.Name, self.Args)
				fmt.Printf("%s, and I have arguments: a=%s, b=%s, c=%s\n", self.Name, self.Args["a"], self.Args["b"], self.Args["c"])
			})
			g.Depends("main:hello")
		})
	})

	g.Desc("make a file")
	g.Task("createfile", func(self *g.TaskInfo) {
		txt :=
			`this is 
the 
file contents`
		WriteFile("output.txt", txt)
	})

	g.Default("main:hello")
}