Esempio n. 1
0
File: main.go Progetto: tav/bolt
func (r Registry) Main(ctx *Context, args []string) {
	opts := optparse.Parser("Usage: bolt <command-1> <command-2> ... [options]\n", "bolt 0.1")
	opts.String([]string{"--boltfile"}, "",
		"use the Boltfile at the given path", "PATH")
	opts.String([]string{"--gen"}, "",
		"save the generated executable at the given path", "PATH")
	opts.Bool([]string{"--recompile"}, false,
		"recompile the generated executable instead of using cached builds")
	noConsoleLog := opts.BoolConfig("no-console-log", false,
		"disable logging to the console [false]")
	completions := append(ctx.completions, r.Keys()...)
	opts.Completer = optparse.ListCompleter(completions...)
	opts.Parse(args)
	if len(args) == 1 {
		listing := r.Listing()
		fmt.Print(listing)
		runtime.Exit(0)
	}
	if !*noConsoleLog {
		log.AddConsoleLogger()
	}
	buf := &bytes.Buffer{}
	yaml.NormaliseID(buf, args[1])
	cmd := buf.String()
	if task, ok := r[cmd]; ok {
		task.Func.Call([]reflect.Value{reflect.ValueOf(ctx)})
	} else {
		fmt.Printf("Task not found:\n\n\t%s\n\n", args[1])
		runtime.Exit(1)
	}
}
Esempio n. 2
0
File: main.go Progetto: tav/bolt
func RegisterAt(registry Registry, id, doc string, task interface{}) error {
	rv := reflect.ValueOf(task)
	rt := rv.Type()
	if rt.Kind() != reflect.Func {
		return InvalidRegistration
	}
	buf := &bytes.Buffer{}
	yaml.NormaliseID(buf, id)
	registry[buf.String()] = &Task{Doc: doc, Func: rv}
	return nil
}