Merge pull request #108 from lqmanh/features/make-parent-dirs-as-needed

Make parent directories as needed
This commit is contained in:
long2ice 2020-12-25 22:10:56 +08:00 committed by GitHub
commit 78a15f9f19
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -240,8 +240,7 @@ async def init(
with open(config_file, "w", encoding="utf-8") as f:
parser.write(f)
if not Path(location).is_dir():
os.mkdir(location)
Path(location).mkdir(parents=True, exist_ok=True)
click.secho(f"Success create migrate location {location}", fg=Color.green)
click.secho(f"Success generate config file {config_file}", fg=Color.green)
@ -263,10 +262,10 @@ async def init_db(ctx: Context, safe):
app = ctx.obj["app"]
dirname = Path(location, app)
if not dirname.is_dir():
os.mkdir(dirname)
try:
dirname.mkdir(parents=True)
click.secho(f"Success create app migrate location {dirname}", fg=Color.green)
else:
except FileExistsError:
return click.secho(
f"Inited {app} already, or delete {dirname} and try again.", fg=Color.yellow
)