mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 11:18:54 -05:00
[Core] Various fixes to redbot-setup delete (#2958)
- ``redbot-setup delete`` no longer errors about "unexpected keyword argument" (fix #2955) - ``redbot-setup delete`` no longer prompts about backup when user passes ``--no-prompt`` option (fix #2956) - ``--[no-]backup``, ``--[no-]drop-db`` and ``--[no-]remove-datapath`` in ``redbot-setup delete`` command are now on/off flags. ``--no-prompt`` was changed to flag too, but it doesn't have ``--prompt`` equivalent as there's no much point in having it - ``redbot-setup`` now uses `click.confirm` for confirmation prompts and thy now also have default values for user convenience
This commit is contained in:
parent
26cc85806e
commit
b490942bcd
1
changelog.d/2955.bugfix.rst
Normal file
1
changelog.d/2955.bugfix.rst
Normal file
@ -0,0 +1 @@
|
|||||||
|
``redbot-setup delete`` no longer errors about "unexpected keyword argument"
|
||||||
1
changelog.d/2956.bugfix.rst
Normal file
1
changelog.d/2956.bugfix.rst
Normal file
@ -0,0 +1 @@
|
|||||||
|
``redbot-setup delete`` no longer prompts about backup when user passes ``--no-prompt`` option
|
||||||
1
changelog.d/2958.enhance.1.rst
Normal file
1
changelog.d/2958.enhance.1.rst
Normal file
@ -0,0 +1 @@
|
|||||||
|
``--[no-]backup``, ``--[no-]drop-db`` and ``--[no-]remove-datapath`` in ``redbot-setup delete`` command are now on/off flags.
|
||||||
1
changelog.d/2958.enhance.2.rst
Normal file
1
changelog.d/2958.enhance.2.rst
Normal file
@ -0,0 +1 @@
|
|||||||
|
Confirmation prompts in ``redbot-setup`` now have default values for user convenience.
|
||||||
@ -12,8 +12,7 @@ import appdirs
|
|||||||
import click
|
import click
|
||||||
|
|
||||||
import redbot.logging
|
import redbot.logging
|
||||||
from redbot.core.cli import confirm
|
from redbot.core.utils import safe_delete, create_backup as red_create_backup
|
||||||
from redbot.core.utils import safe_delete, create_backup as _create_backup
|
|
||||||
from redbot.core import config, data_manager, drivers
|
from redbot.core import config, data_manager, drivers
|
||||||
from redbot.core.drivers import BackendType, IdentifierData
|
from redbot.core.drivers import BackendType, IdentifierData
|
||||||
|
|
||||||
@ -59,7 +58,9 @@ def save_config(name, data, remove=False):
|
|||||||
"WARNING: An instance already exists with this name. "
|
"WARNING: An instance already exists with this name. "
|
||||||
"Continuing will overwrite the existing instance config."
|
"Continuing will overwrite the existing instance config."
|
||||||
)
|
)
|
||||||
if not confirm("Are you absolutely certain you want to continue (y/n)? "):
|
if not click.confirm(
|
||||||
|
"Are you absolutely certain you want to continue?", default=False
|
||||||
|
):
|
||||||
print("Not continuing")
|
print("Not continuing")
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
_config[name] = data
|
_config[name] = data
|
||||||
@ -100,7 +101,7 @@ def get_data_dir():
|
|||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
print("You have chosen {} to be your data directory.".format(default_data_dir))
|
print("You have chosen {} to be your data directory.".format(default_data_dir))
|
||||||
if not confirm("Please confirm (y/n):"):
|
if not click.confirm("Please confirm", default=True):
|
||||||
print("Please start the process over.")
|
print("Please start the process over.")
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
return default_data_dir
|
return default_data_dir
|
||||||
@ -258,18 +259,18 @@ async def edit_instance():
|
|||||||
|
|
||||||
current_data_dir = Path(_instance_data["DATA_PATH"])
|
current_data_dir = Path(_instance_data["DATA_PATH"])
|
||||||
print("You have selected '{}' as the instance to modify.".format(selected))
|
print("You have selected '{}' as the instance to modify.".format(selected))
|
||||||
if not confirm("Please confirm (y/n):"):
|
if not click.confirm("Please confirm", default=True):
|
||||||
print("Ok, we will not continue then.")
|
print("Ok, we will not continue then.")
|
||||||
return
|
return
|
||||||
|
|
||||||
print("Ok, we will continue on.")
|
print("Ok, we will continue on.")
|
||||||
print()
|
print()
|
||||||
if confirm("Would you like to change the instance name? (y/n)"):
|
if click.confirm("Would you like to change the instance name?", default=False):
|
||||||
name = get_name()
|
name = get_name()
|
||||||
else:
|
else:
|
||||||
name = selected
|
name = selected
|
||||||
|
|
||||||
if confirm("Would you like to change the data location? (y/n)"):
|
if click.confirm("Would you like to change the data location?", default=False):
|
||||||
default_data_dir = get_data_dir()
|
default_data_dir = get_data_dir()
|
||||||
default_dirs["DATA_PATH"] = str(default_data_dir.resolve())
|
default_dirs["DATA_PATH"] = str(default_data_dir.resolve())
|
||||||
else:
|
else:
|
||||||
@ -290,7 +291,7 @@ async def create_backup(instance: str) -> None:
|
|||||||
elif backend_type != BackendType.JSON:
|
elif backend_type != BackendType.JSON:
|
||||||
await do_migration(backend_type, BackendType.JSON)
|
await do_migration(backend_type, BackendType.JSON)
|
||||||
print("Backing up the instance's data...")
|
print("Backing up the instance's data...")
|
||||||
backup_fpath = await _create_backup()
|
backup_fpath = await red_create_backup()
|
||||||
if backup_fpath is not None:
|
if backup_fpath is not None:
|
||||||
print(f"A backup of {instance} has been made. It is at {backup_fpath}")
|
print(f"A backup of {instance} has been made. It is at {backup_fpath}")
|
||||||
else:
|
else:
|
||||||
@ -300,12 +301,18 @@ async def create_backup(instance: str) -> None:
|
|||||||
async def remove_instance(
|
async def remove_instance(
|
||||||
instance,
|
instance,
|
||||||
interactive: bool = False,
|
interactive: bool = False,
|
||||||
|
_create_backup: Optional[bool] = None,
|
||||||
drop_db: Optional[bool] = None,
|
drop_db: Optional[bool] = None,
|
||||||
remove_datapath: Optional[bool] = None,
|
remove_datapath: Optional[bool] = None,
|
||||||
):
|
):
|
||||||
data_manager.load_basic_configuration(instance)
|
data_manager.load_basic_configuration(instance)
|
||||||
|
|
||||||
if confirm("Would you like to make a backup of the data for this instance? (y/n)"):
|
if interactive is True and _create_backup is None:
|
||||||
|
_create_backup = click.confirm(
|
||||||
|
"Would you like to make a backup of the data for this instance?", default=False
|
||||||
|
)
|
||||||
|
|
||||||
|
if _create_backup is True:
|
||||||
await create_backup(instance)
|
await create_backup(instance)
|
||||||
|
|
||||||
backend = get_current_backend(instance)
|
backend = get_current_backend(instance)
|
||||||
@ -317,7 +324,9 @@ async def remove_instance(
|
|||||||
await driver_cls.delete_all_data(interactive=interactive, drop_db=drop_db)
|
await driver_cls.delete_all_data(interactive=interactive, drop_db=drop_db)
|
||||||
|
|
||||||
if interactive is True and remove_datapath is None:
|
if interactive is True and remove_datapath is None:
|
||||||
remove_datapath = confirm("Would you like to delete the instance's entire datapath? (y/n)")
|
remove_datapath = click.confirm(
|
||||||
|
"Would you like to delete the instance's entire datapath?", default=False
|
||||||
|
)
|
||||||
|
|
||||||
if remove_datapath is True:
|
if remove_datapath is True:
|
||||||
data_path = data_manager.core_data_path().parent
|
data_path = data_manager.core_data_path().parent
|
||||||
@ -360,32 +369,52 @@ def cli(ctx, debug):
|
|||||||
|
|
||||||
@cli.command()
|
@cli.command()
|
||||||
@click.argument("instance", type=click.Choice(instance_list))
|
@click.argument("instance", type=click.Choice(instance_list))
|
||||||
@click.option("--no-prompt", default=False, help="Don't ask for user input during the process.")
|
|
||||||
@click.option(
|
@click.option(
|
||||||
"--drop-db",
|
"--no-prompt",
|
||||||
type=bool,
|
"interactive",
|
||||||
|
is_flag=True,
|
||||||
|
default=True,
|
||||||
|
help="Don't ask for user input during the process.",
|
||||||
|
)
|
||||||
|
@click.option(
|
||||||
|
"--backup/--no-backup",
|
||||||
|
"_create_backup",
|
||||||
|
is_flag=True,
|
||||||
|
default=None,
|
||||||
|
help=(
|
||||||
|
"Create backup of this instance's data. "
|
||||||
|
"If these options and --no-prompt are omitted, you will be asked about this."
|
||||||
|
),
|
||||||
|
)
|
||||||
|
@click.option(
|
||||||
|
"--drop-db/--no-drop-db",
|
||||||
|
is_flag=True,
|
||||||
default=None,
|
default=None,
|
||||||
help=(
|
help=(
|
||||||
"Drop the entire database constaining this instance's data. Has no effect on JSON "
|
"Drop the entire database constaining this instance's data. Has no effect on JSON "
|
||||||
"instances. If this option and --no-prompt are omitted, you will be asked about this."
|
"instances. If these options and --no-prompt are omitted, you will be asked about this."
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
@click.option(
|
@click.option(
|
||||||
"--remove-datapath",
|
"--remove-datapath/--no-remove-datapath",
|
||||||
type=bool,
|
is_flag=True,
|
||||||
default=None,
|
default=None,
|
||||||
help=(
|
help=(
|
||||||
"Remove this entire instance's datapath. If this option and --no-prompt are omitted, you "
|
"Remove this entire instance's datapath. If these options and --no-prompt are omitted, "
|
||||||
"will be asked about this."
|
"you will be asked about this."
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
def delete(instance: str, no_prompt: Optional[bool], drop_db: Optional[bool]):
|
def delete(
|
||||||
|
instance: str,
|
||||||
|
interactive: bool,
|
||||||
|
_create_backup: Optional[bool],
|
||||||
|
drop_db: Optional[bool],
|
||||||
|
remove_datapath: Optional[bool],
|
||||||
|
):
|
||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_event_loop()
|
||||||
if no_prompt is None:
|
loop.run_until_complete(
|
||||||
interactive = None
|
remove_instance(instance, interactive, _create_backup, drop_db, remove_datapath)
|
||||||
else:
|
)
|
||||||
interactive = not no_prompt
|
|
||||||
loop.run_until_complete(remove_instance(instance, interactive, drop_db))
|
|
||||||
|
|
||||||
|
|
||||||
@cli.command()
|
@cli.command()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user