From cea5f5a9ed275f804c73e0ae116fe70f93ea672c Mon Sep 17 00:00:00 2001 From: Lev Vereshchagin Date: Wed, 23 Feb 2022 12:30:59 +0300 Subject: [PATCH] Make pretend bench catch unknown commands (closes #666) --- build/worker/patched_bench_helper.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/build/worker/patched_bench_helper.py b/build/worker/patched_bench_helper.py index 8c69dbdd..e4631118 100644 --- a/build/worker/patched_bench_helper.py +++ b/build/worker/patched_bench_helper.py @@ -1,3 +1,5 @@ +import click +import click.exceptions import frappe.app import frappe.database.db_manager import frappe.utils.bench_helper @@ -14,8 +16,28 @@ def patch_database_creator(): frappe.database.db_manager.DbManager.get_current_host = lambda self: "%" +def patch_click_usage_error(): + bits: tuple[str, ...] = ( + click.style( + "Only Frappe framework bench commands are available in container setup.", + fg="yellow", + bold=True, + ), + "https://frappeframework.com/docs/v13/user/en/bench/frappe-commands", + ) + notice = "\n".join(bits) + + def format_message(self: click.exceptions.UsageError): + if "No such command" in self.message: + return f"{notice}\n\n{self.message}" + return self.message + + click.exceptions.UsageError.format_message = format_message + + def main() -> int: patch_database_creator() + patch_click_usage_error() frappe.utils.bench_helper.main() return 0