Exemple #1
0
func callMe(out clif.Output, in clif.Input, c *clif.Command, foo MyFoo, baz *MyBaz) {
	barIn := in.Ask("Gimme a bar integer: ", func(v string) error {
		_, err := strconv.Atoi(v)
		return err
	})
	barInt, _ := strconv.Atoi(barIn)
	foo.SetBar(barInt)

	bazIn := in.AskRegex("Now please a baz: ", regexp.MustCompile(`^B`))
	baz.baz = bazIn

	out.Printf("Bar: <info>%s<reset>\nBaz: <headline>%s<reset>\n", foo.Bar(), baz)
}
Exemple #2
0
func callIn(in clif.Input, out clif.Output) {
	name := in.Ask("Who are you?", func(v string) error {
		if len(v) > 0 {
			return nil
		} else {
			return fmt.Errorf("Didn't catch that")
		}
	})
	out.Printf("\n")
	father := ""
	for {
		father = in.Choose(fmt.Sprintf("Hello %s. Who is your father?", name), map[string]string{
			"yoda":  "The small, green guy",
			"darth": "The one with the dark cloark and a smokers voice",
			"obi":   "The old man with the light thingy",
		})
		if in.Confirm("You're sure about that? (y/n)") {
			break
		} else {
			out.Printf("\n")
		}
	}

	out.Printf("Well, <important>%s<reset>, ", name)
	if father != "darth" {
		out.Printf("<success>may the force be with you!<reset>\n")
	} else {
		out.Printf("<error>NOOOOOOOO!<reset>\n")
	}
}