forked from Michelle-Wanderi/AirBnB_clone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconsole.py
executable file
·77 lines (54 loc) · 1.96 KB
/
console.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/python3
#To see it in action cd into the airbnb console directory then run python commandline.py or python3 commandline.py in your terminal
# The command interpeter
import cmd
from models.base_model import BaseModel
from models import storage
class HBNBCommand(cmd.Cmd):
"""Contains functionality of the console"""
intro = 'Welcome to the interpreter! Type help or ? to list commands.\n'
prompt = '(hbnb) '
def do_hello(self, line):
"""Says hello to the user"""
print("Hello!")
def do_create(self, line):
"""Creates a new object"""
print("Create a new object")
if len(line)==0:
print("**PLease write the name of the class")
elif line not in HBNBCommand.classes:
print("Class does not exist")
else:
instance = eval(line)()
instance.save()
print(instance.id)
def do_update(self, line):
"""Updates attributes of an object"""
print("Update attributes of an object")
def do_destroy(self, line, args):
"""Destroys an object"""
print("Destroy an object")
obj_list = []
if len(line) == 0:
for objs in storage.all().values():
obj_list.append(objs)
print(obj_list)
elif args[0] in HBNBCommand.classes:
for key, objs in storage.all().items():
if args[0] in key:
obj_list.append(objs)
print(obj_list)
else:
print("class doesnt exist")
def do_operations(self,args):
"""Do operations on objects"""
print("Choose operation to use on object")
def do_EOF(self, arg):
""" Handles EOF to exit program """
print()
def do_quit(self, args):
"""Quits the interpreter"""
print("Goodbye!")
return True
if __name__ == '__main__':
HBNBCommand().cmdloop()