"""
Office Space Allocator.

Usage:
  allocator create_room <room_type> <room_name>...
  allocator add_person <person_name> <person_surname> <person_type> [<wants_accommodation>]

Options:
  -h --help                         Show this screen.
  --version                         Show version.

Examples:
  allocator create_room office Blue
  allocator add_person Nelly Armweek Fellow Y

"""

import cmd
from docopt import docopt, DocoptExit
from classes.dojo import Dojo

dojo = Dojo()


def deco(f):
    """
    This decorator is used to simplify the try/except block and pass the result
    of the docopt parsing to the called action.
    """
    def fn(self, arg):
        try:
            opt = docopt(fn.__doc__, arg)

        except DocoptExit as e:
            # The DocoptExit is thrown when the args do not match.
            # We print a message to the user and the usage block.
            print('Invalid Command!')
            print(e)
            return

        except SystemExit:
            # The SystemExit exception prints the usage for --help
            return

        return f(self, opt)

    fn.__name__ = f.__name__
    fn.__doc__ = f.__doc__
    fn.__dict__.update(f.__dict__)
    return fn


class MyInteractive(cmd.Cmd):
    intro = 'Welcome to the Office Space Allocator!' \
        + ' (Type help for a list of commands.)'
    prompt = '(allocator) '

    @deco
    def do_create_room(self, arg):
        """Usage: create_room <room_type> <room_name>..."""
        arguments = arg
        # print (arguments)
        if arguments['<room_name>'] and arguments['<room_type>']:
            for room_name in arguments['<room_name>']:
                dojo.create_room(arguments['<room_type>'], room_name)

    @deco
    def do_add_person(self, arg):
        """Usage: add_person <person_name> <person_surname> <person_type> [<wants_accommodation>]"""
        arguments = arg
        # print (arguments)
        if arguments['<person_name>']:
            if arguments['<person_type>'] and arguments['<person_type>'].lower() == 'staff':
                dojo.add_person(arguments['<person_type>'], arguments['<person_name>'], arguments['<person_surname>'])
                new_staff = dojo.all_persons[-1]
                dojo.allocate_rooms()
            elif arguments['<person_type>'] and arguments['<person_type>'].lower() == 'fellow':
                if arguments['<wants_accommodation>']:
                    dojo.add_person(arguments['<person_type>'], arguments['<person_name>'], arguments['<person_surname>'], arguments['<wants_accommodation>'])
                    new_fellow = dojo.all_persons[-1]
                    dojo.allocate_rooms()
                else:
                    dojo.add_person(arguments['<person_type>'], arguments['<person_name>'], arguments['<person_surname>'])
                    new_fellow = dojo.all_persons[-1]
                    dojo.allocate_rooms()


if __name__ == '__main__':
    MyInteractive().cmdloop()

@@ -171,16 +171,33 @@
 dation%3E%5D
+%0A  allocator exit
 %0A%0AOption
@@ -402,16 +402,27 @@
 Y%0A%0A%22%22%22%0A%0A
+import sys%0A
 import c
@@ -701,95 +701,19 @@
     
-try:%0A            opt = docopt(fn.__doc__, arg)%0A%0A        except DocoptExit as e:
+%22%22%22
 %0A       
     
@@ -704,30 +704,24 @@
  %22%22%22%0A       
-     #
  The DocoptE
@@ -769,22 +769,16 @@
 %0A       
-     #
  We prin
@@ -822,16 +822,177 @@
  block.%0A
+        The SystemExit exception prints the usage for --help%0A        %22%22%22%0A        try:%0A            opt = docopt(fn.__doc__, arg)%0A%0A        except DocoptExit as e:%0A
         
@@ -1093,75 +1093,8 @@
 it:%0A
-            # The SystemExit exception prints the usage for --help%0A
     
@@ -1291,64 +1291,208 @@
 o = 
-'Welcome to the Office Space Allocator!' %5C%0A        + ' (
+('* ' * 10) + 'WELCOME TO THE OFFICE SPACE ALLOCATOR!' + (' *' * 10)%5C%0A        + '%5Cn' + ('= ' * 7) + 'the easiest way to handle all your room allocation.' + (' =' * 7) %5C%0A        + '%5Cn' + (' ' * 23) + '
 Type
@@ -1523,10 +1523,8 @@
 ands
-.)
 '%0A  
@@ -1687,36 +1687,25 @@
         
-# print (arguments)%0A
+try:%0A    
         
@@ -1774,16 +1774,20 @@
         
+  
+  
 for room
@@ -1813,32 +1813,36 @@
 '%3Croom_name%3E'%5D:%0A
+    
                 
@@ -1894,16 +1894,111 @@
 om_name)
+%0A                    dojo.allocate_rooms()%0A        except Exception as e:%0A            print (e)
 %0A%0A    @d
@@ -2172,512 +2172,98 @@
     
-# print (arguments)%0A        if arguments%5B'%3Cperson_name%3E'%5D:%0A            if arguments%5B'%3Cperson_type%3E'%5D and arguments%5B'%3Cperson_type%3E'%5D.lower() == 'staff':%0A                dojo.add_person(arguments%5B'%3Cperson_type%3E'%5D, arguments%5B'%3Cperson_name%3E'%5D, arguments%5B'%3Cperson_surname%3E'%5D)%0A                new_staff = dojo.all_persons%5B-1%5D%0A                dojo.allocate_rooms()%0A            elif arguments%5B'%3Cperson_type%3E'%5D and arguments%5B'%3Cperson_type%3E'%5D.lower() == 'fellow':%0A                if arguments%5B'%3Cwants_accommodation
+try:%0A            if arguments%5B'%3Cperson_name%3E'%5D:%0A                if arguments%5B'%3Cperson_type
 %3E'%5D:
@@ -2530,243 +2530,169 @@
     
-        else:%0A                    dojo.add_person(arguments%5B'%3Cperson_type%3E'%5D, arguments%5B'%3Cperson_name%3E'%5D, arguments%5B'%3Cperson_surname%3E'%5D)%0A                    new_fellow = dojo.all_persons%5B-1%5D%0A                    dojo.allocate_rooms
+except Exception as e:%0A            print (e)%0A%0A    @deco%0A    def do_exit(self, arg):%0A        %22%22%22Usage: exit%22%22%22%0A        print ('Have a nice day!')%0A        exit
 ()%0A%0A
-%0A
 if _
@@ -2714,16 +2714,29 @@
 ain__':%0A
+    try:%0A    
     MyIn
@@ -2757,8 +2757,88 @@
 dloop()%0A
+    except KeyboardInterrupt:%0A        print ('Have a nice day!')%0A        exit()%0A

Add smooth exit functionality even with Ctrl-C