Skip to content

Commit 49287ba

Browse files
committed
feat: support environment set
1 parent 1c5bd0e commit 49287ba

File tree

4 files changed

+27
-11
lines changed

4 files changed

+27
-11
lines changed

.idea/.gitignore

Lines changed: 0 additions & 8 deletions
This file was deleted.

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# ChangeLog
2+
3+
## 0.1
4+
5+
### 0.1.0
6+
7+
- First release.

README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,19 @@ TORTOISE_ORM = {
5050
Then you can start an interactive shell for TortoiseORM.
5151

5252
```shell
53-
tortoise-cli -c examples.TORTOISE_ORM shell
53+
tortoise-cli -c settings.TORTOISE_ORM shell
54+
```
55+
56+
Or you can set config by set environment variable.
57+
58+
```shell
59+
export TORTOISE_ORM=settings.TORTOISE_ORM
60+
```
61+
62+
Then just run:
63+
64+
```shell
65+
tortoise-cli shell
5466
```
5567

5668
## License

tortoise_cli/cli.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import asyncio
2+
import os
23
from functools import wraps
4+
from typing import Optional
35

46
import click
57
from ptpython.repl import embed
@@ -27,11 +29,14 @@ def wrapper(*args, **kwargs):
2729
"-c",
2830
"--config",
2931
help="TortoiseORM config dictionary path, like settings.TORTOISE_ORM",
30-
required=True,
3132
)
3233
@click.pass_context
3334
@coro
34-
async def cli(ctx: click.Context, config: str):
35+
async def cli(ctx: click.Context, config: Optional[str]):
36+
if not config:
37+
config = os.getenv("TORTOISE_ORM")
38+
if not config:
39+
raise click.UsageError("You must specify TORTOISE_ORM in option or env", ctx=ctx)
3540
tortoise_config = utils.get_tortoise_config(ctx, config)
3641
await Tortoise.init(config=tortoise_config)
3742
await Tortoise.generate_schemas(safe=True)

0 commit comments

Comments
 (0)