Exemple #1
0
func NameFromController(c Controller) string {
	name := reflect.TypeOf(c).Elem().Name()
	matches := controllerName.FindStringSubmatch(name)
	if matches == nil || len(matches) != 2 {
		panic(`Controller names must adhere to the convention of '<name>Controller'`)
	}
	return strings.ToLower(strutil.Hyphenate(matches[1]))
}
Exemple #2
0
func Add(commands ...Command) {
	for _, c := range commands {
		t := reflect.TypeOf(c).Elem()
		v := reflect.ValueOf(c).Elem()
		flagger := v.FieldByName("Flagger")
		flagger.Set(reflect.ValueOf(&Flagger{&flag.FlagSet{}}))
		name := strutil.Hyphenate(t.Name())
		commandSet[name] = c
		if len(os.Args) > 1 && name == os.Args[1] && name != "help" {
			if Global != nil {
				Global(c.GetFlagSet())
			}
			c.SetFlags()
			c.Parse(os.Args[2:])
		}
	}
}
Exemple #3
0
func arbitraryActions(ctlr Controller) (actions [][]string) {
	t := reflect.TypeOf(ctlr)
	v := reflect.ValueOf(ctlr)
	for i := 0; i < t.NumMethod(); i++ {
		method := t.Method(i)
		if method.PkgPath == "" && isAction(v.Method(i)) {
			isDefault := false
			name := strutil.Hyphenate(method.Name)
			for _, da := range defaultActions {
				if name == da {
					isDefault = true
				}
			}
			if !isDefault {
				actions = append(actions, []string{name, method.Name})
			}
		}
	}
	return
}
Exemple #4
0
//hyphenate should convert "PascalCase" into "pascal-case"
func (s *ControllerSuite) TestHyphenateShouldConvertPascalcaseIntoPascalcase(c *C) {
	c.Assert(strutil.Hyphenate("PascalCase"), Equals, "pascal-case")
}