github.com/jacobsoderblom/buffalo@v0.11.0/generators/resource/props.go (about)

     1  package resource
     2  
     3  import (
     4  	"strings"
     5  
     6  	"github.com/markbates/inflect"
     7  )
     8  
     9  // Prop of a model. Starts as name:type on the command line.
    10  type Prop struct {
    11  	Name inflect.Name
    12  	Type string
    13  }
    14  
    15  // String representation of Prop
    16  func (m Prop) String() string {
    17  	return string(m.Name)
    18  }
    19  
    20  func modelPropertiesFromArgs(args []string) []Prop {
    21  	var props []Prop
    22  	if len(args) == 0 {
    23  		return props
    24  	}
    25  	for _, a := range args[1:] {
    26  		ax := strings.Split(a, ":")
    27  		p := Prop{
    28  			Name: inflect.Name(inflect.ForeignKeyToAttribute(ax[0])),
    29  			Type: "string",
    30  		}
    31  		if len(ax) > 1 {
    32  			p.Type = strings.ToLower(strings.TrimPrefix(ax[1], "nulls."))
    33  		}
    34  		props = append(props, p)
    35  	}
    36  	return props
    37  }