This project is the first step towards building a full web application of the AirBnB clone. In this first step we are building a console, a custom command interpreter that will be used in subsequent AirBnB projects to manage objects of our classes.
This console will allow us to do the following:
- Create a
new object
- Retrieve an object from a
file, a database etc…
- Do operations on objects (count, compute stats, etc…)
- Update attributes of an object
- Destroy an object
- The console can be run in both interactive and non-interactive mode.
- It prints a prompt (hbnb) and waits for the user for input.
$ ./console.py
(hbnb) help
Documented commands (type help <topic>):
========================================
EOF help quit
(hbnb)
(hbnb)
(hbnb) quit
$
$ echo "help" | ./console.py
(hbnb)
Documented commands (type help <topic>):
========================================
EOF help quit
(hbnb)
$
$ cat test_help
help
$
$ cat test_help | ./console.py
(hbnb)
Documented commands (type help <topic>):
========================================
EOF help quit
(hbnb)
$
Command | Description |
---|---|
quit |
Exits the program |
EOF |
Exits the program |
create <class> |
Creates an instance of a class |
show <class> <id> |
Prints the string representation of an instance of a class based on class name and id |
destroy <class> <id> |
Deletes instance of a class based on class name and id |
all |
Prints all string representations of all instances |
all <class> |
Prints all string representations of all instances based on class name |
update <class> <id> <attribute name> "<attribute value>" |
Updates an attribute of an instance based on class name and id |
<class>.all() |
Retrieves all instances of a class |
<class>.count() |
Retrieves the number of instances of a class |
<class>.show(<id>) |
Retrieves an instance based on its id |
<class>.destroy(<id>) |
Destroys an instance based on its id |
All codes are tested with the unittest module. The tests are in thetest_models
folder.
- Ahmed Samy - Ahmed