Пример #1
0
func parseCommands() (cmds []cli.Command, err error) {
	source, err := os.Getwd()
	if err != nil {
		return
	}

	parser := build.NewParser()
	taskSet, err := parser.Parse(source)
	if err != nil {
		return
	}

	for _, t := range taskSet.Tasks {
		task := t
		cmd := cli.Command{
			Name:        task.Name,
			Usage:       task.Usage,
			Description: task.Description,
			Flags:       append(t.ToCLIFlags(), debugFlag),
			Action: func(c *cli.Context) {
				err := runTasks(os.Args[1:], c.Bool("debug"))
				if err != nil {
					log.Fatal(err)
				}
			},
		}

		cmds = append(cmds, cmd)
	}

	return
}
Пример #2
0
func parseCommands() (cmds []cli.Command, err error) {
	source, err := os.Getwd()
	if err != nil {
		return
	}

	parser := build.NewParser()
	taskSet, err := parser.Parse(source)
	if err != nil {
		return
	}

	for _, t := range taskSet.Tasks {
		task := t
		cmd := cli.Command{
			Name:        task.Name,
			Usage:       task.Usage,
			Description: task.Description,
			Action: func(c *cli.Context) {
				args := []string{task.Name}
				args = append(args, c.Args()...)
				err := runTasks(args)
				if err != nil {
					log.Fatal(err)
				}
			},
		}

		cmds = append(cmds, cmd)
	}

	return
}