Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add force parameter to create #1870

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changes/1870.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added force flag to create command to overwrite existing scaffolds
7 changes: 6 additions & 1 deletion docs/reference/commands/create.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,9 @@ to delete and regenerate the app.
Options
=======

There are no additional command line options.
The following options can be provided at the command line.

``--force``
---------------------------------------

Automatically overwrite any existing scaffold for the nominated platform instead of asking for confirmation.
26 changes: 22 additions & 4 deletions src/briefcase/commands/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@ def app_template_url(self) -> str:
"""The URL for a cookiecutter repository to use when creating apps."""
return f"https://github.com/beeware/briefcase-{self.platform}-{self.output_format}-template.git"

def add_options(self, parser):
parser.add_argument(
"--force",
action="store_true",
help="Automatically confirm overwriting existing scaffold",
)

def support_package_filename(self, support_revision: str) -> str:
"""The query arguments to use in a support package query request."""
return f"Python-{self.python_version_tag}-{self.platform}-support.b{support_revision}.tar.gz"
Expand Down Expand Up @@ -858,19 +865,27 @@ def cleanup_app_content(self, app: AppConfig):
self.logger.verbose(f"Removing {relative_path}")
path.unlink()

def create_app(self, app: AppConfig, test_mode: bool = False, **options):
def create_app(
self,
app: AppConfig,
test_mode: bool = False,
auto_confirm: bool = False,
**options,
):
"""Create an application bundle.

:param app: The config object for the app
:param test_mode: Should the app be updated in test mode? (default: False)
:param auto_confirm: Should any existing scaffold be automatically overwritten?
(default: False)
"""
if not app.supported:
raise UnsupportedPlatform(self.platform)

bundle_path = self.bundle_path(app)
if bundle_path.exists():
self.logger.info()
confirm = self.input.boolean_input(
confirm = auto_confirm or self.input.boolean_input(
f"Application {app.app_name!r} already exists; overwrite", default=False
)
if not confirm:
Expand Down Expand Up @@ -935,18 +950,21 @@ def verify_app_tools(self, app: AppConfig):
def __call__(
self,
app: AppConfig | None = None,
auto_overwrite: bool = False,
**options,
) -> dict | None:
# Confirm host compatibility, that all required tools are available,
# and that the app configuration is finalized.
self.finalize(app)

if app:
state = self.create_app(app, **options)
state = self.create_app(app, auto_overwrite, **options)
else:
state = None
for app_name, app in sorted(self.apps.items()):
state = self.create_app(app, **full_options(state, options))
state = self.create_app(
app, auto_overwrite, **full_options(state, options)
)

return state

Expand Down
Loading