Commit 0ecf6d6a authored by Edward Lesmes's avatar Edward Lesmes Committed by Commit Bot

gclient setdep: Command line interface nits.

'setdep' now shows as a command when typing 'gclient help'.
We now use parser errors to indicate invalid formatting of flags, and
raise an error when there are unused arguments.

R=agable@chromium.org

Bug: 760633
Change-Id: I37fa65ef0c2cff9de1234efcf22bcd888a5e9589
Reviewed-on: https://chromium-review.googlesource.com/998741
Commit-Queue: Edward Lesmes <ehmaldonado@chromium.org>
Reviewed-by: 's avatarMichael Moss <mmoss@chromium.org>
Reviewed-by: 's avatarAaron Gable <agable@chromium.org>
parent dbd6476c
......@@ -2937,6 +2937,7 @@ def CMDrevinfo(parser, args):
def CMDsetdep(parser, args):
"""Modifies dependency revisions and variable values in a DEPS file"""
parser.add_option('--var', action='append',
dest='vars', metavar='VAR=VAL', default=[],
help='Sets a variable to the given value with the format '
......@@ -2956,6 +2957,11 @@ def CMDsetdep(parser, args):
help='The DEPS file to be edited. Defaults to the DEPS '
'file in the current directory.')
(options, args) = parser.parse_args(args)
if args:
parser.error('Unused arguments: "%s"' % '" "'.join(args))
if not options.revisions and not options.vars:
parser.error(
'You must specify at least one variable or revision to modify.')
if not os.path.isfile(options.deps_file):
raise gclient_utils.Error(
......@@ -2969,7 +2975,7 @@ def CMDsetdep(parser, args):
for var in options.vars:
name, _, value = var.partition('=')
if not name or not value:
raise gclient_utils.Error(
parser.error(
'Wrong var format: %s should be of the form name=value.' % var)
if name in local_scope['vars']:
gclient_eval.SetVar(local_scope, name, value)
......@@ -2979,12 +2985,12 @@ def CMDsetdep(parser, args):
for revision in options.revisions:
name, _, value = revision.partition('@')
if not name or not value:
raise gclient_utils.Error(
parser.error(
'Wrong dep format: %s should be of the form dep@rev.' % revision)
if ':' in name:
name, _, package = name.partition(':')
if not name or not package:
raise gclient_utils.Error(
parser.error(
'Wrong CIPD format: %s:%s should be of the form path:pkg@version.'
% (name, package))
gclient_eval.SetCIPD(local_scope, name, package, value)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment