github.com/sleungcy-sap/cli@v7.1.0+incompatible/cf/requirements/number_arguments.go (about)

     1  package requirements
     2  
     3  import (
     4  	"strings"
     5  
     6  	. "code.cloudfoundry.org/cli/cf/i18n"
     7  )
     8  
     9  type NumberArguments struct {
    10  	passedArgs   []string
    11  	expectedArgs []string
    12  }
    13  
    14  func NewNumberArguments(passedArgs []string, expectedArgs []string) Requirement {
    15  	return NumberArguments{
    16  		passedArgs:   passedArgs,
    17  		expectedArgs: expectedArgs,
    18  	}
    19  }
    20  
    21  func (r NumberArguments) Execute() error {
    22  	if len(r.passedArgs) != len(r.expectedArgs) {
    23  		return NumberArgumentsError{ExpectedArgs: r.expectedArgs}
    24  	}
    25  
    26  	return nil
    27  }
    28  
    29  type NumberArgumentsError struct {
    30  	ExpectedArgs []string
    31  }
    32  
    33  func (e NumberArgumentsError) Error() string {
    34  	return T("Incorrect Usage. Requires {{.Arguments}}", map[string]string{
    35  		"Arguments": strings.Join(e.ExpectedArgs, ", "),
    36  	})
    37  }