Esempio n. 1
0
func (c *TesterCommand) Run(args []string) int {

	c.Ui = &cli.PrefixedUi{
		OutputPrefix: "==> ",
		InfoPrefix:   "    ",
		ErrorPrefix:  "==> ",
		Ui:           c.Ui,
	}

	var color string
	var ledName string

	cmdFlags := flag.NewFlagSet("agent", flag.ContinueOnError)
	cmdFlags.Usage = func() { c.Ui.Output(c.Help()) }
	cmdFlags.StringVar(&color, "color", "", "set the led to this color")
	cmdFlags.StringVar(&ledName, "ledname", "", "name of the led to set")

	if err := cmdFlags.Parse(args); err != nil {
		return 1
	}

	if color == "" {
		c.Ui.Error("color flag required")
		return 1
	}

	if leds.Colors[color] == nil {
		c.Ui.Error("Invalid color supplied")
		return 1
	}

	if !leds.ValidLedName(ledName) {
		c.Ui.Error("Invalid led name supplied")
		return 1
	}

	c.ledArray = leds.CreateLedArray()
	c.Ui.Output("Sphere LEDs tester")
	c.Ui.Info(fmt.Sprintf("Setting power %s to: %s", ledName, color))
	c.ledArray.SetColor(leds.LedNameIndex(ledName), color, true)
	c.ledArray.SetLEDs()

	return 0
}
Esempio n. 2
0
func createAgent(conf *Config) *Agent {
	return &Agent{conf: conf, memstats: &runtime.MemStats{}, leds: leds.CreateLedArray()}
}