upload: add support for --yes

This adds a CLI option to the existing autoupload gitconfig knob that
allows people to automatically answer "yes" to the various prompts.

Bug: https://crbug.com/gerrit/12368
Change-Id: I819ebca01b9a40240b33866ae05907c7469703e3
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/255892
Reviewed-by: David Pursehouse <dpursehouse@collab.net>
Tested-by: Mike Frysinger <vapier@google.com>
This commit is contained in:
Mike Frysinger 2020-02-19 02:32:52 -05:00
parent 819cc81c57
commit 02aa889ecd

View File

@ -184,6 +184,9 @@ Gerrit Code Review: https://www.gerritcodereview.com/
p.add_option('-n', '--dry-run', p.add_option('-n', '--dry-run',
dest='dryrun', default=False, action='store_true', dest='dryrun', default=False, action='store_true',
help='Do everything except actually upload the CL.') help='Do everything except actually upload the CL.')
p.add_option('-y', '--yes',
default=False, action='store_true',
help='Answer yes to all safe prompts.')
p.add_option('--no-cert-checks', p.add_option('--no-cert-checks',
dest='validate_certs', action='store_false', default=True, dest='validate_certs', action='store_false', default=True,
help='Disable verifying ssl certs (unsafe).') help='Disable verifying ssl certs (unsafe).')
@ -244,6 +247,10 @@ Gerrit Code Review: https://www.gerritcodereview.com/
print('to %s (y/N)? ' % remote.review, end='') print('to %s (y/N)? ' % remote.review, end='')
# TODO: When we require Python 3, use flush=True w/print above. # TODO: When we require Python 3, use flush=True w/print above.
sys.stdout.flush() sys.stdout.flush()
if opt.yes:
print('<--yes>')
answer = True
else:
answer = sys.stdin.readline().strip().lower() answer = sys.stdin.readline().strip().lower()
answer = answer in ('y', 'yes', '1', 'true', 't') answer = answer in ('y', 'yes', '1', 'true', 't')
@ -384,6 +391,10 @@ Gerrit Code Review: https://www.gerritcodereview.com/
print('Continue uploading? (y/N) ', end='') print('Continue uploading? (y/N) ', end='')
# TODO: When we require Python 3, use flush=True w/print above. # TODO: When we require Python 3, use flush=True w/print above.
sys.stdout.flush() sys.stdout.flush()
if opt.yes:
print('<--yes>')
a = 'yes'
else:
a = sys.stdin.readline().strip().lower() a = sys.stdin.readline().strip().lower()
if a not in ('y', 'yes', 't', 'true', 'on'): if a not in ('y', 'yes', 't', 'true', 'on'):
print("skipping upload", file=sys.stderr) print("skipping upload", file=sys.stderr)