github.com/sleungcy-sap/cli@v7.1.0+incompatible/cf/requirements/usage_requirement.go (about) 1 package requirements 2 3 import ( 4 "errors" 5 "fmt" 6 7 . "code.cloudfoundry.org/cli/cf/i18n" 8 ) 9 10 type RequirementFunction func() error 11 12 func (f RequirementFunction) Execute() error { 13 return f() 14 } 15 16 func NewUsageRequirement(cmd Usable, errorMessage string, pred func() bool) Requirement { 17 return RequirementFunction(func() error { 18 if pred() { 19 m := fmt.Sprintf("%s. %s\n\n%s", T("Incorrect Usage"), errorMessage, cmd.Usage()) 20 21 return errors.New(m) 22 } 23 24 return nil 25 }) 26 } 27 28 type Usable interface { 29 Usage() string 30 }