github.com/jghiloni/cli@v6.28.1-0.20170628223758-0ce05fe032a2+incompatible/command/flag/org_role.go (about)

     1  package flag
     2  
     3  import (
     4  	"strings"
     5  
     6  	flags "github.com/jessevdk/go-flags"
     7  )
     8  
     9  type OrgRole struct {
    10  	Role string
    11  }
    12  
    13  func (_ OrgRole) Complete(prefix string) []flags.Completion {
    14  	return completions([]string{"OrgManager", "BillingManager", "OrgAuditor"}, prefix, false)
    15  }
    16  
    17  func (o *OrgRole) UnmarshalFlag(val string) error {
    18  	switch strings.ToLower(val) {
    19  	case "orgauditor":
    20  		o.Role = "OrgAuditor"
    21  	case "billingmanager":
    22  		o.Role = "BillingManager"
    23  	case "orgmanager":
    24  		o.Role = "OrgManager"
    25  	default:
    26  		return &flags.Error{
    27  			Type:    flags.ErrRequired,
    28  			Message: `ROLE must be "OrgManager", "BillingManager" and "OrgAuditor"`,
    29  		}
    30  	}
    31  
    32  	return nil
    33  }