Improve command-line descriptions

Changed CLI help texts for some of the options to make them clearer.
This commit is contained in:
Merlin 2024-08-07 13:31:07 -04:00 committed by GitHub
parent 15d56121ef
commit dbf96a17d3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -37,7 +37,7 @@ async def cli(ctx: Context, config, app) -> None:
if invoked_subcommand != "init":
config_path = Path(config)
if not config_path.exists():
raise UsageError("You must exec init first", ctx=ctx)
raise UsageError("You need to run `aerich init` first to create the config file.", ctx=ctx)
content = config_path.read_text()
doc: dict = tomlkit.parse(content)
try:
@ -46,7 +46,7 @@ async def cli(ctx: Context, config, app) -> None:
tortoise_orm = tool["tortoise_orm"]
src_folder = tool.get("src_folder", CONFIG_DEFAULT_VALUES["src_folder"])
except NonExistentKey:
raise UsageError("You need run aerich init again when upgrade to 0.6.0+")
raise UsageError("You need run `aerich init` again when upgrading to aerich 0.6.0+.")
add_src_path(src_folder)
tortoise_config = get_tortoise_config(ctx, tortoise_orm)
if not app:
@ -56,29 +56,29 @@ async def cli(ctx: Context, config, app) -> None:
ctx.obj["command"] = command
if invoked_subcommand != "init-db":
if not Path(location, app).exists():
raise UsageError("You must exec init-db first", ctx=ctx)
raise UsageError("You need to run `aerich init-db` first to initialize the database.", ctx=ctx)
await command.init()
@cli.command(help="Generate migrate changes file.")
@click.option("--name", default="update", show_default=True, help="Migrate name.")
@click.option("--empty", default=False, is_flag=True, help="Generate empty migration file.")
@cli.command(help="Generate a migration file for the current state of the models.")
@click.option("--name", default="update", show_default=True, help="Migration name.")
@click.option("--empty", default=False, is_flag=True, help="Generate an empty migration file.")
@click.pass_context
async def migrate(ctx: Context, name, empty) -> None:
command = ctx.obj["command"]
ret = await command.migrate(name, empty)
if not ret:
return click.secho("No changes detected", fg=Color.yellow)
click.secho(f"Success migrate {ret}", fg=Color.green)
click.secho(f"Successfully created migration file {ret}", fg=Color.green)
@cli.command(help="Upgrade to specified version.")
@cli.command(help="Upgrade to specified migration version.")
@click.option(
"--in-transaction",
"-i",
default=True,
type=bool,
help="Make migrations in transaction or not. Can be helpful for large migrations or creating concurrent indexes.",
help="Make migrations in a single transaction or not. Can be helpful for large migrations or creating concurrent indexes.",
)
@click.pass_context
async def upgrade(ctx: Context, in_transaction: bool) -> None:
@ -88,7 +88,7 @@ async def upgrade(ctx: Context, in_transaction: bool) -> None:
click.secho("No upgrade items found", fg=Color.yellow)
else:
for version_file in migrated:
click.secho(f"Success upgrade {version_file}", fg=Color.green)
click.secho(f"Success upgrading to {version_file}", fg=Color.green)
@cli.command(help="Downgrade to specified version.")
@ -97,8 +97,8 @@ async def upgrade(ctx: Context, in_transaction: bool) -> None:
"--version",
default=-1,
type=int,
show_default=True,
help="Specified version, default to last.",
show_default=False,
help="Specified version, default to last migration.",
)
@click.option(
"-d",
@ -106,11 +106,11 @@ async def upgrade(ctx: Context, in_transaction: bool) -> None:
is_flag=True,
default=False,
show_default=True,
help="Delete version files at the same time.",
help="Also delete the migration files.",
)
@click.pass_context
@click.confirmation_option(
prompt="Downgrade is dangerous, which maybe lose your data, are you sure?",
prompt="Downgrade is dangerous: you might lose your data! Are you sure?",
)
async def downgrade(ctx: Context, version: int, delete: bool) -> None:
command = ctx.obj["command"]
@ -119,43 +119,43 @@ async def downgrade(ctx: Context, version: int, delete: bool) -> None:
except DowngradeError as e:
return click.secho(str(e), fg=Color.yellow)
for file in files:
click.secho(f"Success downgrade {file}", fg=Color.green)
click.secho(f"Success downgrading to {file}", fg=Color.green)
@cli.command(help="Show current available heads in migrate location.")
@cli.command(help="Show currently available heads (unapplied migrations).")
@click.pass_context
async def heads(ctx: Context) -> None:
command = ctx.obj["command"]
head_list = await command.heads()
if not head_list:
return click.secho("No available heads, try migrate first", fg=Color.green)
return click.secho("No available heads.", fg=Color.green)
for version in head_list:
click.secho(version, fg=Color.green)
@cli.command(help="List all migrate items.")
@cli.command(help="List all migrations.")
@click.pass_context
async def history(ctx: Context) -> None:
command = ctx.obj["command"]
versions = await command.history()
if not versions:
return click.secho("No history, try migrate", fg=Color.green)
return click.secho("No migrations created yet.", fg=Color.green)
for version in versions:
click.secho(version, fg=Color.green)
@cli.command(help="Init config file and generate root migrate location.")
@cli.command(help="Initialize aerich config and create migrations folder.")
@click.option(
"-t",
"--tortoise-orm",
required=True,
help="Tortoise-ORM config module dict variable, like settings.TORTOISE_ORM.",
help="Tortoise-ORM config dict location, like `settings.TORTOISE_ORM`.",
)
@click.option(
"--location",
default="./migrations",
show_default=True,
help="Migrate store location.",
help="Migrations folder.",
)
@click.option(
"-s",
@ -193,18 +193,18 @@ async def init(ctx: Context, tortoise_orm, location, src_folder) -> None:
Path(location).mkdir(parents=True, exist_ok=True)
click.secho(f"Success create migrate location {location}", fg=Color.green)
click.secho(f"Success write config to {config_file}", fg=Color.green)
click.secho(f"Success creating migrations folder {location}", fg=Color.green)
click.secho(f"Success writing aerich config to {config_file}", fg=Color.green)
@cli.command(help="Generate schema and generate app migrate location.")
@cli.command(help="Generate schema and generate app migration folder.")
@click.option(
"-s",
"--safe",
type=bool,
is_flag=True,
default=True,
help="When set to true, creates the table only when it does not already exist.",
help="Create tables only when they do not already exist.",
show_default=True,
)
@click.pass_context
@ -214,15 +214,15 @@ async def init_db(ctx: Context, safe: bool) -> None:
dirname = Path(command.location, app)
try:
await command.init_db(safe)
click.secho(f"Success create app migrate location {dirname}", fg=Color.green)
click.secho(f'Success generate schema for app "{app}"', fg=Color.green)
click.secho(f"Success creating app migration folder {dirname}", fg=Color.green)
click.secho(f'Success generating initial migration file for app "{app}"', fg=Color.green)
except FileExistsError:
return click.secho(
f"Inited {app} already, or delete {dirname} and try again.", fg=Color.yellow
f"App {app} is already initialized. Delete {dirname} and try again.", fg=Color.yellow
)
@cli.command(help="Introspects the database tables to standard output as TortoiseORM model.")
@cli.command(help="Prints the current database tables to stdout as Tortoise-ORM models.")
@click.option(
"-t",
"--table",