Skip to content

Commit 6a50d38

Browse files
authored
Merge pull request #31 from eadwinCode/cli_help_command_fix
Cli help command fix
2 parents 108592f + 00b8bdf commit 6a50d38

File tree

7 files changed

+65
-13
lines changed

7 files changed

+65
-13
lines changed

.github/workflows/publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
- name: Set up Python
1414
uses: actions/setup-python@v4
1515
with:
16-
python-version: 3.6
16+
python-version: 3.8
1717
- name: Install Flit
1818
run: pip install flit
1919
- name: Install Dependencies

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ test-cov: ## Run tests with coverage
3636

3737
doc-deploy: ## Run Deploy Documentation
3838
make clean
39-
mkdocs gh-deploy --force
39+
mkdocs gh-deploy --force --ignore-version
4040

4141

4242
pre-commit-lint: ## Runs Requires commands during pre-commit

docs/quick-start.md

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,14 @@ pip install ellar
2929
## Create a project
3030
To create an ellar project, you need to have a `pyproject.toml` available on your root directory.
3131
This is necessary for ellar to store some `metadata` about your project.
32+
3233
### Step 1
3334
For Pip Users, you need to create `pyproject.toml` file
3435
```shell
3536
touch pyproject.toml
3637
```
3738
If you are using `Poetry`, you are ready to go
39+
3840
### Step 2
3941
Run the ellar create project cli command,
4042
```shell
@@ -51,6 +53,7 @@ ellar runserver --reload
5153
Now go to [http://127.0.0.1:8000](http://127.0.0.1:8000)
5254
![Swagger UI](img/ellar_framework.png)
5355

56+
5457
## Create a project module
5558
A project module is a project app defining a group of controllers or services including templates and static files.
5659
So, now we have a project created, lets add an app to the project.
@@ -59,7 +62,7 @@ ellar create-module car
5962
```
6063

6164
## Add Schema
62-
In `car.schema.py`, lets add some serializer for car input and output data
65+
In `car/schema.py`, lets add some serializer for car input and output data
6366
```python
6467
from ellar.serializer import Serializer
6568

@@ -74,7 +77,7 @@ class RetrieveCarSerializer(CarSerializer):
7477
```
7578

7679
## Add Services
77-
In `car.services.py`, lets create a dummy repository `CarDummyDB` to manage our car data.
80+
In `car/services.py`, lets create a dummy repository `CarDummyDB` to manage our car data.
7881
```python
7982
import typing as t
8083
import uuid
@@ -127,7 +130,7 @@ class CarDummyDB:
127130
return self._data.pop(idx)
128131
```
129132
## Add Controller
130-
In `car.controllers.py`, lets create `CarController`
133+
In `car/controllers.py`, lets create `CarController`
131134

132135
```python
133136
import typing as t
@@ -175,7 +178,7 @@ class CarController(ControllerBase):
175178

176179
```
177180
## Register Service and Controller
178-
In `car.module.py`, lets register `CarController` and `CarDummyDB`
181+
In `car/module.py`, lets register `CarController` and `CarDummyDB`
179182

180183
```python
181184
from ellar.common import Module
@@ -198,9 +201,27 @@ class CarModule(ModuleBase):
198201
pass
199202
```
200203

204+
## Registering Module
205+
Ellar is not aware of `CarModule` yet, so we need to add it to the `modules` list of `ApplicationModule` at the `carsite/root_module.py`.
206+
```python
207+
from ellar.common import Module, exception_handler
208+
from ellar.core import ModuleBase
209+
from ellar.core.connection import Request
210+
from ellar.core.response import JSONResponse, Response
201211

202-
## Enabling OpenAPI
203-
To start up openapi, we need to go back to project folder in the `carsite.server.py`
212+
from ellar.samples.modules import HomeModule
213+
from .apps.car.module import CarModule
214+
215+
216+
@Module(modules=[HomeModule, CarModule])
217+
class ApplicationModule(ModuleBase):
218+
@exception_handler(404)
219+
def exception_404_handler(cls, request: Request, exc: Exception) -> Response:
220+
return JSONResponse(dict(detail="Resource not found."))
221+
222+
```
223+
## Enabling OpenAPI Docs
224+
To start up openapi, we need to go back to project folder in the `server.py`
204225
then add the following below.
205226
```python
206227
import os

ellar/cli/_main.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@ def build_typers() -> None:
4444
options, args = getopt.getopt(
4545
sys.argv[1:],
4646
"p:",
47-
[
48-
"project=",
49-
],
47+
["project=", "help"],
5048
)
5149
app_name: t.Optional[str] = None
5250

tests/test_cli/sample_app/example_project_2/commands.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,9 @@ def create_migration():
1414
def whatever_you_want():
1515
"""Whatever you want"""
1616
print("Whatever you want command from example_project_2")
17+
18+
19+
@command()
20+
def project_2_command():
21+
"""Project 2 Custom Command"""
22+
print("Project 2 Custom Command from example_project_2")

tests/test_cli/sample_app/example_project_2/root_module.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
from ellar.core.connection import Request
44
from ellar.core.response import JSONResponse, Response
55

6-
from .commands import db, whatever_you_want
6+
from .commands import db, project_2_command, whatever_you_want
77

88

9-
@Module(commands=[db, whatever_you_want])
9+
@Module(commands=[db, whatever_you_want, project_2_command])
1010
class ApplicationModule(ModuleBase):
1111
@exception_handler(404)
1212
def exception_404_handler(cls, request: Request, exc: Exception) -> Response:

tests/test_cli/test_build_typers.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,30 @@ def test_build_typers_command_for_specific_project_works():
5252
)
5353
assert result.returncode == 0
5454
assert result.stdout == b"Whatever you want command from example_project_2\n"
55+
56+
57+
def test_help_command(cli_runner):
58+
os.chdir(sample_app_path)
59+
result = subprocess.run(["ellar", "--help"], stdout=subprocess.PIPE)
60+
assert result.returncode == 0
61+
assert (
62+
result.stdout
63+
== b"Usage: Ellar, Python Web framework [OPTIONS] COMMAND [ARGS]...\n\nOptions:\n -p, --project TEXT Run Specific Command on a specific project\n --install-completion [bash|zsh|fish|powershell|pwsh]\n Install completion for the specified shell.\n --show-completion [bash|zsh|fish|powershell|pwsh]\n Show completion for the specified shell, to\n copy it or customize the installation.\n --help Show this message and exit.\n\nCommands:\n create-module - Scaffolds Ellar Application Module -\n create-project - Scaffolds Ellar Application -\n db\n runserver - Starts Uvicorn Server -\n say-hi\n whatever-you-want Whatever you want\n"
64+
)
65+
result = subprocess.run(
66+
["ellar", "-p", "example_project", "--help"], stdout=subprocess.PIPE
67+
)
68+
assert result.returncode == 0
69+
assert (
70+
result.stdout
71+
== b"Usage: Ellar, Python Web framework [OPTIONS] COMMAND [ARGS]...\n\nOptions:\n -p, --project TEXT Run Specific Command on a specific project\n --install-completion [bash|zsh|fish|powershell|pwsh]\n Install completion for the specified shell.\n --show-completion [bash|zsh|fish|powershell|pwsh]\n Show completion for the specified shell, to\n copy it or customize the installation.\n --help Show this message and exit.\n\nCommands:\n create-module - Scaffolds Ellar Application Module -\n create-project - Scaffolds Ellar Application -\n db\n runserver - Starts Uvicorn Server -\n say-hi\n whatever-you-want Whatever you want\n"
72+
)
73+
74+
result = subprocess.run(
75+
["ellar", "-p", "example_project_2", "--help"], stdout=subprocess.PIPE
76+
)
77+
assert result.returncode == 0
78+
assert (
79+
result.stdout
80+
== b"Usage: Ellar, Python Web framework [OPTIONS] COMMAND [ARGS]...\n\nOptions:\n -p, --project TEXT Run Specific Command on a specific project\n --install-completion [bash|zsh|fish|powershell|pwsh]\n Install completion for the specified shell.\n --show-completion [bash|zsh|fish|powershell|pwsh]\n Show completion for the specified shell, to\n copy it or customize the installation.\n --help Show this message and exit.\n\nCommands:\n create-module - Scaffolds Ellar Application Module -\n create-project - Scaffolds Ellar Application -\n db\n project-2-command Project 2 Custom Command\n runserver - Starts Uvicorn Server -\n say-hi\n whatever-you-want Whatever you want\n"
81+
)

0 commit comments

Comments
 (0)