Decorator used to specify an argument taken by the console script.
    Positional and keyword arguments have the same meaning as those
    given to ``argparse.ArgumentParser.add_argument()``.
548880
def argument(*args, **kwargs):
    

    def decorator(func):
        adaptor = ScriptAdaptor._get_adaptor(func)
        group = kwargs.pop('group', None)
        adaptor._add_argument(args, kwargs, group=group)
        return func
    return decorator
461714
def infer_argument(self, funcnode, name, context):
        
        if name in self.duplicated_keywords:
            raise exceptions.InferenceError(
                "The arguments passed to {func!r} " " have duplicate keywords.",
                call_site=self,
                func=funcnode,
                arg=name,
                context=context,
            )

        # Look into the keywords first, maybe it's already there.
        try:
            return self.keyword_arguments[name].infer(context)
        except KeyError:
            pass

        # Too many arguments given and no variable arguments.
        if len(self.positional_arguments) > len(funcnode.args.args):
            if not funcnode.args.vararg:
                raise exceptions.InferenceError(
                    "Too many positional arguments "
                    "passed to {func!r} that does "
                    "not have *args.",
                    call_site=self,
                    func=funcnode,
                    arg=name,
                    context=context,
                )

        positional = self.positional_arguments[: len(funcnode.args.args)]
        vararg = self.positional_arguments[len(funcnode.args.args) :]
        argindex = funcnode.args.find_argname(name)[0]
        kwonlyargs = {arg.name for arg in funcnode.args.kwonlyargs}
        kwargs = {
            key: value
            for key, value in self.keyword_arguments.items()
            if key not in kwonlyargs
        }
        # If there are too few positionals compared to
        # what the function expects to receive, check to see
        # if the missing positional arguments were passed
        # as keyword arguments and if so, place them into the
        # positional args list.
        if len(positional) < len(funcnode.args.args):
            for func_arg in funcnode.args.args:
                if func_arg.name in kwargs:
                    arg = kwargs.pop(func_arg.name)
                    positional.append(arg)

        if argindex is not None:
            # 2. first argument of instance/class method
            if argindex == 0 and funcnode.type in ("method", "classmethod"):
                if context.boundnode is not None:
                    boundnode = context.boundnode
                else:
                    # XXX can do better ?
                    boundnode = funcnode.parent.frame()

                if isinstance(boundnode, nodes.ClassDef):
                    # Verify that we're accessing a method
                    # of the metaclass through a class, as in
                    # `cls.metaclass_method`. In this case, the
                    # first argument is always the class.
                    method_scope = funcnode.parent.scope()
                    if method_scope is boundnode.metaclass():
                        return iter((boundnode,))

                if funcnode.type == "method":
                    if not isinstance(boundnode, bases.Instance):
                        boundnode = bases.Instance(boundnode)
                    return iter((boundnode,))
                if funcnode.type == "classmethod":
                    return iter((boundnode,))
            # if we have a method, extract one position
            # from the index, so we'll take in account
            # the extra parameter represented by `self` or `cls`
            if funcnode.type in ("method", "classmethod"):
                argindex -= 1
            # 2. search arg index
            try:
                return self.positional_arguments[argindex].infer(context)
            except IndexError:
                pass

        if funcnode.args.kwarg == name:
            # It wants all the keywords that were passed into
            # the call site.
            if self.has_invalid_keywords():
                raise exceptions.InferenceError(
                    "Inference failed to find values for all keyword arguments "
                    "to {func!r}: {unpacked_kwargs!r} doesn't correspond to "
                    "{keyword_arguments!r}.",
                    keyword_arguments=self.keyword_arguments,
                    unpacked_kwargs=self._unpacked_kwargs,
                    call_site=self,
                    func=funcnode,
                    arg=name,
                    context=context,
                )
            kwarg = nodes.Dict(
                lineno=funcnode.args.lineno,
                col_offset=funcnode.args.col_offset,
                parent=funcnode.args,
            )
            kwarg.postinit(
                [(nodes.const_factory(key), value) for key, value in kwargs.items()]
            )
            return iter((kwarg,))
        if funcnode.args.vararg == name:
            # It wants all the args that were passed into
            # the call site.
            if self.has_invalid_arguments():
                raise exceptions.InferenceError(
                    "Inference failed to find values for all positional "
                    "arguments to {func!r}: {unpacked_args!r} doesn't "
                    "correspond to {positional_arguments!r}.",
                    positional_arguments=self.positional_arguments,
                    unpacked_args=self._unpacked_args,
                    call_site=self,
                    func=funcnode,
                    arg=name,
                    context=context,
                )
            args = nodes.Tuple(
                lineno=funcnode.args.lineno,
                col_offset=funcnode.args.col_offset,
                parent=funcnode.args,
            )
            args.postinit(vararg)
            return iter((args,))

        # Check if it's a default parameter.
        try:
            return funcnode.args.default_value(name).infer(context)
        except exceptions.NoDefault:
            pass
        raise exceptions.InferenceError(
            "No value found for argument {name} to " "{func!r}",
            call_site=self,
            func=funcnode,
            arg=name,
            context=context,
        )
696617
def set_args(self, **kwargs):
        
        try:
            kwargs_items = kwargs.iteritems()
        except AttributeError:
            kwargs_items = kwargs.items()
        for key, val in kwargs_items:
            self.args[key] = val
1249406
def _make_args_checker(self):
        
        def _checker(*args, **kws):
            # Check if too many arguments are provided
            nargs = len(args)
            nnonvaargs = min(nargs, self._max_positional_args)
            if nargs > self._max_positional_args and self._ivararg is None:
                raise self._too_many_args_error(nargs)

            # Check if there are too few positional arguments (without defaults)
            if nargs < self._min_positional_args:
                missing = [p.name
                           for p in self.params[nargs:self._min_positional_args]
                           if p.name not in kws]
                # The "missing" arguments may still be provided as keywords, in
                # which case it's not an error at all.
                if missing:
                    raise self._too_few_args_error(missing, "positional")

            # Check if there are too few required keyword arguments
            if self._required_kwonly_args:
                missing = [kw
                           for kw in self._required_kwonly_args
                           if kw not in kws]
                if missing:
                    raise self._too_few_args_error(missing, "keyword")

            # Check types of positional arguments
            for i, argvalue in enumerate(args):
                param = self.params[i if i < self._max_positional_args else
                                    self._ivararg]
                if param.checker and not (
                    param.checker.check(argvalue) or
                    param.has_default and
                        (argvalue is param.default or argvalue == param.default)
                ):
                    raise self._param_type_error(param, param.name, argvalue)

            # Check types of keyword arguments
            for argname, argvalue in kws.items():
                argindex = self._iargs.get(argname)
                if argindex is not None and argindex < nnonvaargs:
                    raise self._repeating_arg_error(argname)
                index = self._iargs.get(argname)
                if index is None:
                    index = self._ivarkws
                if index is None:
                    s = "%s got an unexpected keyword argument `%s`" % \
                        (self.name_bt, argname)
                    raise self._type_error(s)
                param = self.params[index]
                if param.checker and not (
                    param.checker.check(argvalue) or
                    param.has_default and
                        (argvalue is param.default or argvalue == param.default)
                ):
                    raise self._param_type_error(param, argname, argvalue)

        return _checker
180541
def register_arguments(self, parser):
        
        parser.add_argument('x', type=int, help='the first value')
        parser.add_argument('y', type=int, help='the second value')
588155
def _add_argument(obj, arg):
        
        argparse_options = {name: value for name, value in arg.options.items() if name in ARGPARSE_SUPPORTED_KWARGS}
        if arg.options_list:
            scrubbed_options_list = []
            for item in arg.options_list:

                if isinstance(item, Deprecated):
                    # don't add expired options to the parser
                    if item.expired():
                        continue

                    class _DeprecatedOption(str):
                        def __new__(cls, *args, **kwargs):
                            instance = str.__new__(cls, *args, **kwargs)
                            return instance

                    option = _DeprecatedOption(item.target)
                    setattr(option, 'deprecate_info', item)
                    item = option
                scrubbed_options_list.append(item)
            return obj.add_argument(*scrubbed_options_list, **argparse_options)

        if 'required' in argparse_options:
            del argparse_options['required']
        if 'metavar' not in argparse_options:
            argparse_options['metavar'] = '<{}>'.format(argparse_options['dest'].upper())
        return obj.add_argument(**argparse_options)
67818
def add_arguments(cls, parser, sys_arg_list=None):
        
        parser.add_argument('--icmp_check_interval',
                            dest='icmp_check_interval',
                            required=False, default=2, type=float,
                            help="ICMPecho interval in seconds, default 2 "
                                 "(only for 'icmpecho' health monitor plugin)")
        return ["icmp_check_interval"]
838322
def add_argument(self, *args, parser=None, autoenv=False, env=None,
                     complete=None, **kwargs):
        
        if parser is None:
            parser = self.argparser
        action = parser.add_argument(*args, **kwargs)
        if autoenv:
            if env is not None:
                raise TypeError('Arguments `env` and `autoenv` are mutually '
                                'exclusive')
            env = self._make_autoenv(action)
        if env:
            self.argparser.bind_env(action, env)
            if autoenv:
                self._autoenv_actions.add(action)
        if complete:
            action.complete = complete
        return action
1173079
def _hook_decorator(self, addr, length=0, kwargs=None):
        

        def hook_decorator(func):
            self.hook(addr, func, length=length, kwargs=kwargs)
            return func

        return hook_decorator
1325798
def command(self, *args, **kwargs):
        
        def decorator(f):
            cmd = command(*args, **kwargs)(f)
            self.add_command(cmd)
            return cmd
        return decorator
75709
def argument(*args, **kwargs):
    
    def decorator(f):
        if not hasattr(f, '_arguments'):
            f._arguments = []
        if not hasattr(f, '_argnames'):
            f._argnames = []
        f._arguments.append((args, kwargs))
        f._argnames.append(_get_dest(*args, **kwargs))
        return f
    return decorator
528002
def add_args(self, args):
        
        for key, value in vars(args).items():
            if value is not None:
                setattr(self, key.upper(), value)
109448
def _add_arg(self, key, value, mask=False):
        
        if self.lang == 'python':
            self._add_arg_python(key, value, mask)
        elif self.lang == 'java':
            self._add_arg_java(key, value, mask)
654984
def setup_args(self, parser):
        

        # Add all the arguments to the argument parser
        for args, kwargs in self._arguments:
            parser.add_argument(*args, **kwargs)
610618
def _fill_argparser(self, parser):
        
        for key, val in self._options.items():
            add_argument(parser, key, val)
68455
def _do_create_keywords(args, kw):
    
    v = kw.get('varlist', ())
    # prevent varlist="FOO" from being interpreted as ['F', 'O', 'O']
    if is_String(v): v = (v,)
    kw['varlist'] = tuple(v)
    if args:
        # turn positional args into equivalent keywords
        cmdstrfunc = args[0]
        if cmdstrfunc is None or is_String(cmdstrfunc):
            kw['cmdstr'] = cmdstrfunc
        elif callable(cmdstrfunc):
            kw['strfunction'] = cmdstrfunc
        else:
            raise SCons.Errors.UserError(
                'Invalid command display variable type. '
                'You must either pass a string or a callback which '
                'accepts (target, source, env) as parameters.')
        if len(args) > 1:
            kw['varlist'] = tuple(SCons.Util.flatten(args[1:])) + kw['varlist']
    if kw.get('strfunction', _null) is not _null \
                      and kw.get('cmdstr', _null) is not _null:
        raise SCons.Errors.UserError(
            'Cannot have both strfunction and cmdstr args to Action()')
943896
def argparser_factory(self):
        

        return ArgumentParser(
            prog=self.prog, description=self.__doc__, add_help=False,
        )