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 yes/no options #137

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all 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
33 changes: 27 additions & 6 deletions dbtemplates/management/commands/sync_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,31 @@ 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")
force = options.get("force")
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}"
Expand Down Expand Up @@ -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())
Expand Down