From 3701c40ab181832965437337c68112a44b7fa0e4 Mon Sep 17 00:00:00 2001 From: James Snow Date: Mon, 10 Jan 2022 09:49:18 -0600 Subject: [PATCH] Add a prompt when a user creates a project which shares a name with an existing remote (#50) Fixes a bug where if a user created a project with the same name as an existing remote, the new project would overwrite the existing config which could lead to some confusion. --- webex_skills/cli/project.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/webex_skills/cli/project.py b/webex_skills/cli/project.py index a56df4e..fec7c7c 100644 --- a/webex_skills/cli/project.py +++ b/webex_skills/cli/project.py @@ -35,6 +35,13 @@ def init( ): """Create a new skill project from a template""" + # Check for an existing skill name and provide an option to overwrite + if get_skill_config(skill_name): + if not typer.confirm( + f'A skill named {skill_name} already exists in your configuration. Would you like to overwrite it?' + ): + return + if not secret: typer.secho('Generating secret...') secret = secrets.token_urlsafe(16) @@ -106,9 +113,7 @@ def _create_project( # Create pyproject.toml toml_template = static_path / 'pyproject.toml.tmpl' - toml_content = toml_template.read_text() - - toml_content = toml_content.format(skill_name=skill_name) + toml_content = toml_template.read_text().format(skill_name=skill_name) toml_out_path = output_dir / 'pyproject.toml' toml_out_path.write_text(toml_content)