Skip to content

Commit 5bfebf8

Browse files
authored
Merge pull request #7 from eadwinCode/init_command
Ellar New Project Command
2 parents df9f19f + 12ef661 commit 5bfebf8

30 files changed

+525
-187
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@
99
[![PyPI version](https://badge.fury.io/py/ellar-cli.svg)](https://badge.fury.io/py/ellar-cli)
1010
[![PyPI version](https://img.shields.io/pypi/v/ellar-cli.svg)](https://pypi.python.org/pypi/ellar-cli)
1111
[![PyPI version](https://img.shields.io/pypi/pyversions/ellar-cli.svg)](https://pypi.python.org/pypi/ellar-cli)
12+
13+
Full Documentation: [Here](https://eadwincode.github.io/ellar-cli/)

docs/command-grouping.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
2+
Ella CLI provides a way by which commands can be grouped together.
3+
4+
For instance, a `db` command may have sub-commands like `makemigrations`, `migrate`, `reset-db` etc.
5+
6+
To achieve this use-case, create a file `commands.py` in root project
7+
```python
8+
from ellar.commands import EllarTyper
9+
10+
db = EllarTyper(name="db")
11+
12+
13+
@db.command(name="make-migrations")
14+
def makemigrations():
15+
"""Create DB Migration """
16+
17+
@db.command()
18+
def migrate():
19+
"""Applies Migrations"""
20+
```
21+
in `ApplicationModule`, add the command to `Module` commands parameter
22+
```python
23+
from ellar.common import Module
24+
from ellar.core import ModuleBase
25+
from .commands import db
26+
27+
@Module(commands=[db])
28+
class ApplicationModule(ModuleBase):
29+
pass
30+
```
31+
open your terminal and navigate to project directory and run the command below
32+
```shell
33+
ellar db --help
34+
```
35+
command output
36+
```shell
37+
Usage: Ellar, Python Web framework db [OPTIONS] COMMAND [ARGS]...
38+
39+
Options:
40+
--help Show this message and exit.
41+
42+
Commands:
43+
make-migrations Create DB Migration
44+
migrate Applies Migrations
45+
46+
```

docs/create-module-command.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
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.
4+
5+
```shell
6+
ellar create-module my_project_module
7+
```
8+
9+
will create a folder as follows:
10+
```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
28+
```

docs/create-project-command.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
This command helps you create just an ellar project provided `pyproject.toml` exist in the working directory(`cwd`)
3+
4+
```shell
5+
ellar create-project my_new_project
6+
```
7+
8+
will create a folder as follows:
9+
```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
19+
```

docs/custom-commands.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
This is a quick example of how to create a custom command. Also, hints on working of ella cli.
2+
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.
6+
7+
Create a file `commands.py` in root project
8+
```python
9+
import typing as t
10+
import typer
11+
from ellar.common import command
12+
from ellar_cli.service import EllarCLIService
13+
from ellar_cli.constants import ELLAR_META
14+
15+
@command
16+
def my_new_command(ctx:typer.Context):
17+
"""my_new_command cli description """
18+
ellar_cli_service = t.cast(t.Optional[EllarCLIService], ctx.meta.get(ELLAR_META))
19+
```
20+
`ellar_cli_service` holds ellar project meta-data
21+
Lets, make the `my_new_command` visible on the cli.
22+
23+
In `ApplicationModule`, add the command to `Module` commands parameter
24+
```python
25+
from ellar.common import Module
26+
from ellar.core import ModuleBase
27+
from .commands import my_new_command
28+
29+
@Module(commands=[my_new_command])
30+
class ApplicationModule(ModuleBase):
31+
pass
32+
```
33+
open your terminal and navigate to project directory and run the command below
34+
```shell
35+
ellar db --help
36+
```
37+
command output
38+
```shell
39+
Usage: Ellar, Python Web framework [OPTIONS] COMMAND [ARGS]...
40+
41+
Options:
42+
-p, --project TEXT Run Specific Command on a specific project
43+
--install-completion [bash|zsh|fish|powershell|pwsh]
44+
Install completion for the specified shell.
45+
--show-completion [bash|zsh|fish|powershell|pwsh]
46+
Show completion for the specified shell, to
47+
copy it or customize the installation.
48+
--help Show this message and exit.
49+
50+
Commands:
51+
create-module - Scaffolds Ellar Application Module -
52+
create-project - Scaffolds Ellar Application -
53+
my-new-command my_new_command cli description
54+
new - Runs a complete Ellar project scaffold and creates...
55+
runserver - Starts Uvicorn Server -
56+
say-hi
57+
```

docs/index.md

Lines changed: 18 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -2,117 +2,33 @@
22
<a href="#" target="blank"><img src="img/EllarLogoIconOnly.png" width="200" alt="Ellar Logo" /></a>
33
</p>
44

5-
<p align="center"> Ellar - Python ASGI web framework for building fast, efficient and scalable RESTAPIs and server-side application. </p>
5+
<p align="center"> Ellar CLI Tool for Scaffolding Ellar Projects and Modules and also running Ellar Commands</p>
66

7-
![Test](https://github.com/eadwinCode/ellar/actions/workflows/test_full.yml/badge.svg)
8-
![Coverage](https://img.shields.io/codecov/c/github/eadwinCode/ellar)
9-
[![PyPI version](https://badge.fury.io/py/ellar.svg)](https://badge.fury.io/py/ellar)
10-
[![PyPI version](https://img.shields.io/pypi/v/ellar.svg)](https://pypi.python.org/pypi/ellar)
11-
[![PyPI version](https://img.shields.io/pypi/pyversions/ellar.svg)](https://pypi.python.org/pypi/ellar)
7+
![Test](https://github.com/eadwinCode/ellar-cli/actions/workflows/test_full.yml/badge.svg)
8+
![Coverage](https://img.shields.io/codecov/c/github/eadwinCode/ellar-cli)
9+
[![PyPI version](https://badge.fury.io/py/ellar-cli.svg)](https://badge.fury.io/py/ellar-cli)
10+
[![PyPI version](https://img.shields.io/pypi/v/ellar-cli.svg)](https://pypi.python.org/pypi/ellar-cli)
11+
[![PyPI version](https://img.shields.io/pypi/pyversions/ellar-cli.svg)](https://pypi.python.org/pypi/ellar-cli)
1212

13-
## Features
14-
- Pydantic integration
15-
- DI Container
16-
- Templating with Jinja2
17-
- OpenAPI Documentation (Swagger and ReDoc)
18-
- Controller (MVC)
19-
- Guards (Authentications, roles and permissions)
20-
- Modularization (eg: flask blueprint)
21-
- Websocket support
22-
- Session and Cookie support
23-
- CORS, GZip, Static Files, Streaming responses
24-
- Test client built on `requests`
25-
- In-process background tasks.
26-
- Startup and shutdown events.
27-
- Application Events
28-
- Compatible with `asyncio` and `trio` backends.
13+
# 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.
2915

3016
## Requirements
31-
- Python >= 3.6
32-
- Starlette
33-
- Pydantic
34-
- Injector
17+
- Python >= 3.7
18+
- Ellar
3519

3620
## Installation
37-
21+
if you have [ellar](https://github.com/eadwinCode/ellar) install ready
3822
```
39-
pip install ellar
23+
pip install ellar-cli
4024
```
41-
42-
## Usage
43-
44-
Create a file `controller.py`:
45-
46-
```Python
47-
from ellar.common import ModuleRouter, Controller, get
48-
49-
router = ModuleRouter('', tag='Math')
50-
51-
52-
@router.get("/add")
53-
def add(request, a: int, b: int):
54-
return {"result": a + b}
55-
56-
57-
@Controller("", tag='Math')
58-
class MathAPI:
59-
60-
@get('/subtract', )
61-
def subtract(self, a: int, b: int):
62-
"""Subtracts a from b"""
63-
return {"result": a - b}
64-
65-
@get('/divide', )
66-
def divide(self, a: int, b: int):
67-
"""Divides a by b"""
68-
return {"result": a / b}
69-
70-
@get('/multiple', )
71-
def multiple(self, a: int, b: int):
72-
"""Multiples a with b"""
73-
return {"result": a * b}
74-
25+
Full installation
26+
```shell
27+
pip install ellar-cli[full]
7528
```
7629

77-
Create another file `server.py`:
78-
79-
```Python
80-
from ellar.core import AppFactory
81-
from ellar.openapi import OpenAPIDocumentBuilder, OpenAPIDocumentModule
82-
from .controller import router, MathAPI
83-
84-
85-
app = AppFactory.create_app(routers=(router, ), controllers=(MathAPI, ))
86-
87-
document_builder = OpenAPIDocumentBuilder()
88-
document_builder.set_title('Your Title')\
89-
.set_version('1.0.2')\
90-
.set_contact(name='Eadwin', url='https://www.yahoo.com', email='[email protected]')\
91-
.set_license('MIT Licence', url='https://www.google.com')
92-
93-
document = document_builder.build_document(app)
94-
module = app.install_module(OpenAPIDocumentModule, document=document)
95-
module.setup_swagger_doc()
96-
```
30+
## Usage
9731

98-
### Start up Server
99-
```bash
100-
uvicorn server:app --reload
32+
```shell
33+
ellar --help
10134
```
102-
103-
### Interactive API docs
104-
105-
Now go to <a href="http://localhost:8000/docs/" target="_blank">http://localhost:8000/docs/</a>
106-
107-
You will see the automatic interactive API documentation (provided by <a href="https://github.com/swagger-api/swagger-ui" target="_blank">Swagger UI</a>):
108-
109-
![Swagger UI](img/ellar_demo.gif)
110-
111-
## Status
112-
113-
Project is still in development
114-
115-
- Documentation - in progress
116-
- Database Plugin with [Encode/ORM](https://github.com/encode/orm)
117-
- Caching
118-
- API Throttling

docs/new-command.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
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.
3+
4+
```shell
5+
ellar new my-project
6+
```
7+
8+
will create a folder as follows:
9+
```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
24+
```
25+
If you want to name your project differently than the folder, you can pass the `--project-name` option:
26+
27+
```shell
28+
ellar new my-project --project-name john-doe
29+
```
30+
will create a folder as follows:
31+
```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
46+
```
47+
48+
### New Command CLI Options
49+
- `--project-name` Set the resulting project module name. Defaults to folder-name is not provided.

docs/runserver-command.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
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.
3+
```shell
4+
ellar runserver --reload
5+
```
6+
will product the following output:
7+
```shell
8+
INFO: Will watch for changes in these directories: ['/home/user/working-directory']
9+
INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
10+
INFO: Started reloader process [2934815] using WatchFiles
11+
INFO: APP SETTINGS MODULE: john_doe.config:DevelopmentConfig
12+
INFO: Started server process [2934818]
13+
INFO: Waiting for application startup.
14+
INFO: Application startup complete.
15+
```
16+
17+
### Runserver CLI Options
18+
```shell
19+
ellar runserver --help
20+
```
21+
OR
22+
23+
Please check `Uvicorn` CLI [Options](https://uvicorn.org/#command-line-options)

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.4"
3+
__version__ = "0.0.6"

ellar_cli/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ELLAR_META = "ELLAR_META"

0 commit comments

Comments
 (0)