def validate(self, cmd, messages=None):
        """Returns True if the given Command is valid, False otherwise.
        Validation error messages are appended to an optional messages
        array.
        """
        valid = True
        args  = [ arg for arg in cmd.args if arg is not None ]

        if self.nargs != len(args):
            valid = False
            if messages is not None:
                msg  = 'Expected %d arguments, but received %d.'
                messages.append(msg % (self.nargs, len(args)))

        for defn, value in zip(self.args, cmd.args):
            if value is None:
                valid = False
                if messages is not None:
                    messages.append('Argument "%s" is missing.' % defn.name)
            elif defn.validate(value, messages) is False:
                valid = False

        if len(cmd._unrecognized) > 0:
            valid = False
            if messages is not None:
                for name in cmd.unrecognized:
                    messages.append('Argument "%s" is unrecognized.' % name)

        return valid
def validate ( self , cmd , messages = None ) : valid = True args = [ arg for arg in cmd . args if arg is not None ] if self . nargs != len ( args ) : valid = False if messages is not None : msg = 'Expected %d arguments, but received %d.' messages . append ( msg % ( self . nargs , len ( args ) ) ) for defn , value in zip ( self . args , cmd . args ) : if value is None : valid = False if messages is not None : messages . append ( 'Argument "%s" is missing.' % defn . name ) elif defn . validate ( value , messages ) is False : valid = False if len ( cmd . _unrecognized ) > 0 : valid = False if messages is not None : for name in cmd . unrecognized : messages . append ( 'Argument "%s" is unrecognized.' % name ) return valid
Returns True if the given Command is valid, False otherwise.
        Validation error messages are appended to an optional messages
        array.