Skip to content

Commit 8699f74

Browse files
authored
Merge pull request #12 from eadwinCode/config_changes
Documentation Updates
2 parents 5bfebf8 + a8c2f8f commit 8699f74

File tree

10 files changed

+142
-83
lines changed

10 files changed

+142
-83
lines changed

docs/command-grouping.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11

2-
Ella CLI provides a way by which commands can be grouped together.
2+
Ella CLI provides a way by which commands can be grouped.
33

44
For instance, a `db` command may have sub-commands like `makemigrations`, `migrate`, `reset-db` etc.
55

6-
To achieve this use-case, create a file `commands.py` in root project
6+
To achieve this use-case, let us create a file `commands.py` in the root level of the project.
7+
78
```python
89
from ellar.commands import EllarTyper
910

@@ -18,7 +19,13 @@ def makemigrations():
1819
def migrate():
1920
"""Applies Migrations"""
2021
```
21-
in `ApplicationModule`, add the command to `Module` commands parameter
22+
23+
## Register EllarTyper Command
24+
25+
Lets, make the `db` visible on the CLI.
26+
27+
In other for Ellar CLI to identify custom command, its has to be registered to a `@Module` class.
28+
2229
```python
2330
from ellar.common import Module
2431
from ellar.core import ModuleBase
@@ -28,10 +35,12 @@ from .commands import db
2835
class ApplicationModule(ModuleBase):
2936
pass
3037
```
38+
3139
open your terminal and navigate to project directory and run the command below
3240
```shell
3341
ellar db --help
3442
```
43+
3544
command output
3645
```shell
3746
Usage: Ellar, Python Web framework db [OPTIONS] COMMAND [ARGS]...

docs/create-module-command.md

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,31 @@
11

2-
This command helps you create ellar project module, like a small app within a project.
3-
It depends on the existence of an ellar project.
2+
This command helps you create an Ellar project module, like a small app within a project.
3+
It depends on the existence of an Ellar project.
44

55
```shell
66
ellar create-module my_project_module
77
```
88

99
will create a folder as follows:
1010
```angular2html
11-
john_doe
12-
├── apps
13-
| ├── my_project_module
14-
| | └── __init__.py
15-
| | └── controllers.py
16-
| | └── module.py
17-
| | └── routers.py
18-
| | └── schemas.py
19-
| | └── services.py
20-
| | └── tests
21-
| └── __init__.py
22-
├── core
23-
├── domain
24-
└── __init__.py
25-
└── config.py
26-
└── root_module.py
27-
└── server.py
11+
john_doe/
12+
├─ apps/
13+
│ ├─ my_project_module/
14+
│ │ ├─ tests/
15+
│ │ │ ├─ __init__.py
16+
│ │ ├─ controllers.py
17+
│ │ ├─ module.py
18+
│ │ ├─ routers.py
19+
│ │ ├─ services.py
20+
│ │ ├─ __init__.py
21+
│ ├─ __init__.py
22+
├─ core/
23+
├─ domain/
24+
├─ tests/
25+
│ ├─ __init__.py
26+
├─ __init__.py/
27+
├─ config.py
28+
├─ root_module.py dsssss cxccccccxxcxxnew_file
29+
├─ server.py
30+
2831
```

docs/create-project-command.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11

2-
This command helps you create just an ellar project provided `pyproject.toml` exist in the working directory(`cwd`)
2+
This command helps you create just an Ellar project provided the `"pyproject.toml"` file exists in the working directory(`CWD`)
33

44
```shell
55
ellar create-project my_new_project
66
```
77

88
will create a folder as follows:
99
```angular2html
10-
my_new_project
11-
├─ apps
12-
| └── __init__.py
13-
├─ core
14-
├── domain
15-
└── __init__.py
16-
└── config.py
17-
└── root_module.py
18-
└── server.py
10+
my_new_project/
11+
├─ apps/
12+
│ ├─ __init__.py
13+
├─ core/
14+
├─ config.py
15+
├─ domain
16+
├─ root_module.py
17+
├─ server.py
18+
├─ __init__.py
1919
```

docs/custom-commands.md

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,27 @@
1-
This is a quick example of how to create a custom command. Also, hints on working of ella cli.
1+
In this section, we are going to go over how to create a custom command and throw more light on how Ella CLI works.
22

3-
Ellar CLI tools is a wrapper round [typer](),
4-
so it's easy to get CLI context available in the command action.
5-
Ellar CLI exposes some cli context necessary for validation and interacting with ellar project.
3+
## Create Custom Command
4+
Let's create a file called `commands.py` at the root level of the project.
5+
6+
```python
7+
# project_name/commands.py
8+
9+
from ellar.common import command
10+
11+
@command
12+
def my_new_command():
13+
"""my_new_command cli description """
14+
```
15+
16+
## Custom Command with Context
17+
18+
Ellar CLI tools is a wrapper round [typer](https://typer.tiangolo.com/).
19+
So, therefore, we can easily get the command context by adding a parameter with the annotation of `typer.Context`
20+
21+
Ellar CLI adds some meta-data CLI context that provides an interface for interaction with the Ellar project.
22+
23+
For example:
624

7-
Create a file `commands.py` in root project
825
```python
926
import typing as t
1027
import typer
@@ -14,14 +31,26 @@ from ellar_cli.constants import ELLAR_META
1431

1532
@command
1633
def my_new_command(ctx:typer.Context):
17-
"""my_new_command cli description """
34+
"""my_new_command CLI Description """
1835
ellar_cli_service = t.cast(t.Optional[EllarCLIService], ctx.meta.get(ELLAR_META))
36+
app = ellar_cli_service.import_application()
1937
```
20-
`ellar_cli_service` holds ellar project meta-data
21-
Lets, make the `my_new_command` visible on the cli.
38+
`EllarCLIService` is an Ellar CLI meta-data for interacting with Ellar project.
39+
40+
Some important method that may be of interest:
41+
42+
- `import_application`: returns application instance.
43+
- `get_application_config`: gets current application config.
44+
45+
## Register a Custom Command
46+
47+
Lets, make the `my_new_command` visible on the CLI.
48+
In other for Ellar CLI to identify custom command, its has to be registered to a `@Module` class.
49+
50+
For example:
2251

23-
In `ApplicationModule`, add the command to `Module` commands parameter
2452
```python
53+
# project_name/root_module.py
2554
from ellar.common import Module
2655
from ellar.core import ModuleBase
2756
from .commands import my_new_command
@@ -30,10 +59,12 @@ from .commands import my_new_command
3059
class ApplicationModule(ModuleBase):
3160
pass
3261
```
62+
3363
open your terminal and navigate to project directory and run the command below
3464
```shell
35-
ellar db --help
65+
ellar --help
3666
```
67+
3768
command output
3869
```shell
3970
Usage: Ellar, Python Web framework [OPTIONS] COMMAND [ARGS]...
@@ -50,7 +81,7 @@ Options:
5081
Commands:
5182
create-module - Scaffolds Ellar Application Module -
5283
create-project - Scaffolds Ellar Application -
53-
my-new-command my_new_command cli description
84+
my-new-command - my_new_command cli description
5485
new - Runs a complete Ellar project scaffold and creates...
5586
runserver - Starts Uvicorn Server -
5687
say-hi

docs/index.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
[![PyPI version](https://img.shields.io/pypi/pyversions/ellar-cli.svg)](https://pypi.python.org/pypi/ellar-cli)
1212

1313
# Introduction
14-
Ellar CLI is an abstracted tool for ellar web framework that helps in standard project scaffold of the framework, module project scaffold, runing the project local server using uvicorn and runing custom command registered in application module or any ellar module.
14+
Ellar CLI is an abstracted tool for the Ellar web framework that helps in the standard project scaffold of the framework, module project scaffold, running the project local server using UVICORN, and running custom commands registered in the application module or any Ellar module.
1515

1616
## Requirements
1717
- Python >= 3.7
@@ -23,10 +23,17 @@ if you have [ellar](https://github.com/eadwinCode/ellar) install ready
2323
pip install ellar-cli
2424
```
2525
Full installation
26+
2627
```shell
2728
pip install ellar-cli[full]
2829
```
2930

31+
### NB:
32+
Some shells may treat square braces (`[` and `]`) as special characters. If that's the case here, then use a quote around the characters to prevent unexpected shell expansion.
33+
```shell
34+
pip install "ellar-cli[full]"
35+
```
36+
3037
## Usage
3138

3239
```shell

docs/new-command.md

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,52 @@
11

2-
This command will help you kickstart your new Ellar project by creating a new project with a directory structure and other required files necessary for ellar to properly manage your project.
2+
This command will help you kickstart your new Ellar project.
3+
4+
It creates a new project for you with a directory structure and adds all required files for Ellar CLI to properly manage your project.
35

46
```shell
57
ellar new my-project
68
```
79

810
will create a folder as follows:
911
```angular2html
10-
my-package
11-
├── pyproject.toml
12-
├── README.md
13-
├── my_project
14-
| ├── apps
15-
| | └── __init__.py
16-
| ├── core
17-
| ├── domain
18-
| └── __init__.py
19-
| └── config.py
20-
| └── root_module.py
21-
| └── server.py
22-
└── tests
23-
└── __init__.py
12+
my-project/
13+
├─ my_project/
14+
│ ├─ apps/
15+
│ │ ├─ __init__.py
16+
│ ├─ core/
17+
│ ├─ config.py
18+
│ ├─ domain
19+
│ ├─ root_module.py
20+
│ ├─ server.py
21+
│ ├─ __init__.py
22+
├─ tests/
23+
│ ├─ __init__.py
24+
├─ pyproject.toml
25+
├─ README.md
26+
2427
```
25-
If you want to name your project differently than the folder, you can pass the `--project-name` option:
28+
If you want to name your project differently than the folder, you can pass the `--project-name` option.
2629

2730
```shell
2831
ellar new my-project --project-name john-doe
2932
```
3033
will create a folder as follows:
3134
```angular2html
32-
my-package
33-
├── pyproject.toml
34-
├── README.md
35-
├── john_doe
36-
| ├── apps
37-
| | └── __init__.py
38-
| ├── core
39-
| ├── domain
40-
| └── __init__.py
41-
| └── config.py
42-
| └── root_module.py
43-
| └── server.py
44-
└── tests
45-
└── __init__.py
35+
my-project/
36+
├─ john_doe/
37+
│ ├─ apps/
38+
│ │ ├─ __init__.py
39+
│ ├─ core/
40+
│ ├─ config.py
41+
│ ├─ domain
42+
│ ├─ root_module.py
43+
│ ├─ server.py
44+
│ ├─ __init__.py
45+
├─ tests/
46+
│ ├─ __init__.py
47+
├─ pyproject.toml
48+
├─ README.md
49+
4650
```
4751

4852
### New Command CLI Options

docs/runserver-command.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

2-
This is command is a wrapper around `uvicorn` ASGI server. it helps to create a link necessary for `uvicorn` to run your ellar application properly.
2+
This is command is a wrapper around the `UVICORN` ASGI server. It helps to create a link necessary for `UVICORN` to run your Ellar application properly.
3+
34
```shell
45
ellar runserver --reload
56
```

ellar_cli/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
"""Ellar CLI Tool for Scaffolding Ellar Projects, Modules and also running Ellar Commands"""
22

3-
__version__ = "0.0.6"
3+
__version__ = "0.0.8"

ellar_cli/scaffolding/project_template/project_name/config.ellar

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import typing as t
1010

1111
from pydantic.json import ENCODERS_BY_TYPE as encoders_by_type
1212
from starlette.middleware import Middleware
13-
13+
from ellar.core.exceptions import IExceptionHandler
1414
from ellar.core import ConfigDefaultTypesMixin, JSONResponse
1515
from ellar.core.versioning import BaseAPIVersioning, DefaultAPIVersioning
1616

@@ -45,16 +45,20 @@ class BaseConfig(ConfigDefaultTypesMixin):
4545
# static route path
4646
STATIC_MOUNT_PATH: str = "/static"
4747

48+
CORS_ALLOW_ORIGINS: t.List[str] = ["*"]
49+
CORS_ALLOW_METHODS: t.List[str] = ["*"]
50+
CORS_ALLOW_HEADERS: t.List[str] = ["*"]
51+
ALLOWED_HOSTS: t.List[str] = ["*"]
52+
4853
# Application middlewares
4954
MIDDLEWARE: t.Sequence[Middleware] = []
5055

5156
# A dictionary mapping either integer status codes,
5257
# or exception class types onto callables which handle the exceptions.
5358
# Exception handler callables should be of the form
54-
# `handler(request, exc) -> response` and may be be either standard functions, or async functions.
55-
USER_CUSTOM_EXCEPTION_HANDLERS: t.Dict[
56-
t.Union[int, t.Type[Exception]], t.Callable
57-
] = {}
59+
# `handler(context:IExecutionContext, exc: Exception) -> response`
60+
# and may be either standard functions, or async functions.
61+
EXCEPTION_HANDLERS: t.List[IExceptionHandler] = []
5862

5963
# Object Serializer custom encoders
6064
SERIALIZER_CUSTOM_ENCODER: t.Dict[
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
from ellar.common import Module, exception_handler
22
from ellar.core import ModuleBase
3-
from ellar.core.connection import Request
3+
from ellar.core.context import IExecutionContext
44
from ellar.core.response import JSONResponse, Response
55
from ellar.samples.modules import HomeModule
66

77

88
@Module(modules=[HomeModule])
99
class ApplicationModule(ModuleBase):
1010
@exception_handler(404)
11-
def exception_404_handler(cls, request: Request, exc: Exception) -> Response:
11+
def exception_404_handler(cls, ctx: IExecutionContext, exc: Exception) -> Response:
1212
return JSONResponse(dict(detail="Resource not found."))
1313

0 commit comments

Comments
 (0)