This is the first step towards building our first full web application: the AirBnB clone. This first step is very important because we will use what we build during this project with all other following projects:
- Command interpreter
cmd
- HTML/CSS templating
- database storage
- API
- front-end integration…
- In this project we are tasked to write a command interpreter to manage our AirBnB objects.
What is Command Interpreter?
Command interpreter or cmd
is like a shell It's exactly the same but limited to a specific using, In this project we need a Command interpreter to able to manage the objects of our project like:
- Create a new object (ex: a new User or a new Place)
- 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
To start the command interpreter, run the following command in your terminal:
python3 console.py
Once the command interpreter is running, you can use the following commands:
create <class>: Creates a new instance of the specified class and saves it to the JSON file.
show <class> <id>: Retrieves the instance of the specified class with the given ID.
all <class>: Retrieves all instances of the specified class, or all instances if no class is specified.
update <class> <id> <attribute> <value>: Updates the attribute of the specified class instance with the given ID.
destroy <class> <id>: Deletes the instance of the specified class with the given ID.
Here are some examples of how to use the command interpreter:
(hbnb) create User
(hbnb) show User 1234-5678-9012
(hbnb) all User
(hbnb) update User 1234-5678-9012 name "John Doe"
(hbnb) destroy User 1234-5678-9012
(hbnb) quit
Your shell should work like this in interactive mode:
$ ./console.py
(hbnb) help
Documented commands (type help <topic>):
========================================
EOF help quit
(hbnb)
(hbnb)
(hbnb) quit
$
But also in non-interactive mode: (like the Shell project in C)
$ 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)
$
Kareem Hany