A command-line interface (CLI) that manages data without a visual interface, similar to a shell. The project uses object-oriented programming, Python data translation, and command interpreted logic to deliver a local database that can be modified by commands. The storage engine used is a JSON file. The project provides a console that is used to manage the models in a common AirBnB application.
The console is implemented using the Python library Cmd. The project provides a list of available commands, including create, show, all, update, and destroy, which can be used to manipulate the data in the database.
You need to have Python installed.
To install Python on Arch:
sudo pacman -S python
To install Python on Ubuntu:
sudo apt-get install python
Start using the console
Clone the repository:
git clone https://github.com/uosyph/AirBnB_clone
Move in to the directory:
cd AirBnB_clone
Execute the console:
AirBnB_clone$ python console.py
Or:
AirBnB_clone$ ./console.py
There are test cases for all classes, methods, etc.
To run the tests:
python -m unittest discover tests
To run the tests in non-interactive mode:
echo "python -m unittest discover tests" | bash
To run a specific test file:
python -m unittest tests/test_models/test_base_model.py
The commands available for this command interpreter are:
Command | Description |
---|---|
create | Creates a new instance. |
show | Prints the string representation of an instance. |
destroy | Deletes an instance based on the class name. |
all | Prints string represention of all instances of a given class. |
update | Updates an instance based on the class name and id. |
help | Shows all commands or displays information about a specific command. |
quit | Exits the console. |
EOF | Exits the console. |
The commands available for this command interpreter are:
Command | Description |
---|---|
create | create <class_name> |
show | show <class_name> <object_id> <class_name>.show(<object_id>)() |
destroy | destroy <class_name> <object_id <class_name>.destroy(<object_id>)() |
all | all <class_name> <class_name>.all() |
update | update <class_name> <object_id> <attribute name> "<attribute value>" <class name>.update(<object_id>, <attribute name>, <attribute value>) <class name>.update(<object_id>, <dictionary representation>) |
help | help help <command_name> |
quit | quit |
EOF | EOF CTRL+D |
Example 1: Using create, count and all commands:
AirBnB_clone$ python console.py
(hbnb) all
[]
(hbnb) create Place
f6afd74b-cb6f-45bb-8867-cf73111648ec
(hbnb) create BaseModel
58e430d1-3518-4202-ac4d-5227e5b1d351
(hbnb) BaseModel.count()
1
(hbnb) all
["[Place] (f6afd74b-cb6f-45bb-8867-cf73111648ec) {'id': 'f6afd74b-cb6f-45bb-8867-cf73111648ec', 'created_at': datetime.datetime(2023, 7, 16, 23, 2, 21, 946784), 'updated_at': datetime.datetime(2023, 7, 16, 23, 2, 21, 946784)}", "[BaseModel] (58e430d1-3518-4202-ac4d-5227e5b1d351) {'id': '58e430d1-3518-4202-ac4d-5227e5b1d351', 'created_at': datetime.datetime(2023, 7, 16, 23, 2, 34, 299874), 'updated_at': datetime.datetime(2023, 7, 16, 23, 2, 34, 299874)}"]
(hbnb)
Example 2: Using basic update with an Id and show command:
(hbnb) update BaseModel 58e430d1-3518-4202-ac4d-5227e5b1d351 first_name "Value"
(hbnb) show BaseModel 58e430d1-3518-4202-ac4d-5227e5b1d351
[BaseModel] (58e430d1-3518-4202-ac4d-5227e5b1d351) {'id': '58e430d1-3518-4202-ac4d-5227e5b1d351', 'created_at': datetime.datetime(2023, 7, 16, 23, 2, 34, 299874), 'updated_at': datetime.datetime(2023, 7, 16, 23, 2, 34, 299874), 'first_name': 'Value'}
(hbnb) show Place f6afd74b-cb6f-45bb-8867-cf73111648ec
[Place] (f6afd74b-cb6f-45bb-8867-cf73111648ec) {'id': 'f6afd74b-cb6f-45bb-8867-cf73111648ec', 'created_at': datetime.datetime(2023, 7, 16, 23, 2, 21, 946784), 'updated_at':
datetime.datetime(2023, 7, 16, 23, 2, 21, 946784)}
(hbnb)
Example 3: Using update with a dictionary:
(hbnb) BaseModel.update("58e430d1-3518-4202-ac4d-5227e5b1d351", {'first_name': "yousef", 'age': 21})
(hbnb) show BaseModel 58e430d1-3518-4202-ac4d-5227e5b1d351
[BaseModel] (58e430d1-3518-4202-ac4d-5227e5b1d351) {'id': '58e430d1-3518-4202-ac4d-5227e5b1d351', 'created_at': datetime.datetime(2023, 7, 16, 23, 2, 34, 299874), 'updated_at': datetime.datetime(2023, 7, 16, 23, 2, 34, 299874), 'first_name': 'yousef', 'age': 21}
(hbnb)
Example 4: Using destroy and count command:
(hbnb) BaseModel.destroy("58e430d1-3518-4202-ac4d-5227e5b1d351")
(hbnb) all
["[Place] (f6afd74b-cb6f-45bb-8867-cf73111648ec) {'id': 'f6afd74b-cb6f-45bb-8867-cf73111648ec', 'created_at': datetime.datetime(2023, 7, 16, 23, 2, 21, 946784), 'updated_at': datetime.datetime(2023, 7, 16, 23, 2, 21, 946784)}"]
(hbnb) quit
AirBnB_clone$
AirBnB_clone$ echo "create User" | ./console.py
(hbnb) 5101c62f-88dc-4765-a072-a58c750f9ca5
AirBnB_clone$ echo "show User 5101c62f-88dc-4765-a072-a58c750f9ca5" | ./console.py
(hbnb) [User] (5101c62f-88dc-4765-a072-a58c750f9ca5) {'id': '5101c62f-88dc-4765-a072-a58c750f9ca5', 'created_at': datetime.datetime(2023, 7, 16, 23, 12, 41, 102504), 'updated_at': datetime.datetime(2023, 7, 16, 23, 12, 41, 103200)}
AirBnB_clone$
Distributed under the Apache License Version 2.0. See LICENSE for more information.