diff --git a/dbtemplates/management/commands/sync_templates.py b/dbtemplates/management/commands/sync_templates.py index 7e336e0..3a00d9a 100644 --- a/dbtemplates/management/commands/sync_templates.py +++ b/dbtemplates/management/commands/sync_templates.py @@ -63,6 +63,23 @@ def add_arguments(self, parser): default=False, help="Delete templates after syncing", ) + group = parser.add_mutually_exclusive_group() + group.add_argument( + "-y", + "--yes", + action="store_true", + dest="auto_answer", + default=None, + help="Answer yes to all template creation questions." + ) + group.add_argument( + "-n", + "--no", + action="store_false", + dest="auto_answer", + default=None, + help="Answer no to all template creation questions." + ) def handle(self, **options): extension = options.get("ext") @@ -70,6 +87,7 @@ def handle(self, **options): overwrite = options.get("overwrite") app_first = options.get("app_first") delete = options.get("delete") + auto_answer = options.get('auto_answer') if not extension.startswith("."): extension = f".{extension}" @@ -103,12 +121,15 @@ def handle(self, **options): t = Template.on_site.get(name__exact=name) except Template.DoesNotExist: if not force: - confirm = input( - "\nA '%s' template doesn't exist in the " - "database.\nCreate it with '%s'?" - " (y/[n]): " - "" % (name, path) - ) + if auto_answer is not None: + confirm = "y" if auto_answer else "n" + else: + confirm = input( + "\nA '%s' template doesn't exist in the " + "database.\nCreate it with '%s'?" + " (y/[n]): " + "" % (name, path) + ) if force or confirm.lower().startswith("y"): with open(path, encoding="utf-8") as f: t = Template(name=name, content=f.read())