def execute(self, session: Session, args: Dict[str, Any]) -> ExitCode:
     lookup = args.get('data')
     if lookup is None:
         session.get_io().error('The common data store has not been initialized yet!')
         return ExitCode.FAILURE
     elif len(lookup) == 0:
         session.get_io().error('The common data store does not have any elements in it!')
         return ExitCode.FAILURE
     else:
         return self.command.execute(self=self.command, session=session, args=args)
Exemplo n.º 2
0
def get_integer_from_user(session: Session, message: str, max_attempts: int = 0, retry_delay: int = 1) -> int:
    attempt_count = 0
    while attempt_count <= max_attempts:
        session.get_io().output(message, end='')
        user_input = session.get_io().input()

        try:
            return int(user_input)
        except ValueError:
            session.get_io().error('Your input must be an integer, instead got "{}"'.format(user_input))
            time.sleep(retry_delay)
            session.clear()
            if max_attempts > 0:
                attempt_count += 1
                if attempt_count > max_attempts:
                    raise InputAttemptTimeoutException('Exceeded maximum number of input attempts', max_attempts)
Exemplo n.º 3
0
 def execute(self, session: Session, args: Dict[str, Any]) -> ExitCode:
     session.get_io().output('Exiting program...')
     exit()
     return ExitCode.SUCCESS
Exemplo n.º 4
0
 def execute(self, session: Session, args: Dict[str, Any]) -> ExitCode:
     session.get_io().output('Exiting program...')
     exit()
     return ExitCode.SUCCESS