Beispiel #1
0
func (p *Program) Sprintf(format string, args ...interface{}) string {
	var prefix string
	colorstr, ok := p.config["log.color"].(string)
	if !ok {
		colorstr = ""
	}
	switch colorstr {
	case "black":
		prefix = fmt.Sprintf("[%v] ", api.Black(p.Name))
	case "red":
		prefix = fmt.Sprintf("[%v] ", api.Red(p.Name))
	case "green":
		prefix = fmt.Sprintf("[%v] ", api.Green(p.Name))
	case "blue":
		prefix = fmt.Sprintf("[%v] ", api.Blue(p.Name))
	case "magenta":
		prefix = fmt.Sprintf("[%v] ", api.Magenta(p.Name))
	case "cyan":
		prefix = fmt.Sprintf("[%v] ", api.Cyan(p.Name))
	case "white":
		prefix = fmt.Sprintf("[%v] ", api.White(p.Name))
	case "yellow":
		prefix = fmt.Sprintf("[%v] ", api.Yellow(p.Name))
	default:
		prefix = fmt.Sprintf("[%v] ", p.Name)
	}
	s := fmt.Sprintf(format, args...)
	return prefix + s
}
Beispiel #2
0
func (cmd *HelpCommand) Interpret(c *api.Context) (err error) {
	parts := api.SplitArgs(c.Line, " ")
	if len(parts) < 2 {
		for _, cmd := range c.Commands {
			fmt.Fprintf(c.W, "%-15s %s\n", cmd.Name(), cmd.Description())
		}
	} else {
		cmd := c.Commands[parts[1]]
		fmt.Fprintln(c.W, api.Yellow(cmd.Description()))
		help := cmd.Help()
		if len(strings.Trim(help, " \t\n\r")) > 0 {
			fmt.Fprintln(c.W, help)
		}
		fmt.Fprintf(c.W, "shells: %v\n\n", cmd.Shells())
	}
	return
}