How to use the argcomplete.warn function in argcomplete

To help you get started, we’ve selected a few argcomplete examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github clipos / toolkit / clipostoolkit / cosmk / completion.py View on Github external
"""Returns a list of all the products available in the current repo source
    tree."""

    products = []
    product_globpat = os.path.join(repo_root_path(), "products", "*")
    try:
        for product_path in glob.glob(product_globpat):
            if not os.path.isdir(product_path):
                continue
            _product_path_split = os.path.normpath(product_path).split("/")
            product_name = _product_path_split[-1]
            try:
                product_obj = Product(product_name)
            except Exception as exc:
                exctype = exc.__class__.__name__
                argcomplete.warn(line("""
                    An exception {!r} occured when evaluating product
                    {!r}.""").format(exctype, product_name))
                continue
            products.append(product_name)
    except Exception as exc:
        exctype = exc.__class__.__name__
        argcomplete.warn(line("""
            An exception {!r} occured when enumerating all the available
            products.""").format(exctype))

    return products
github clipos / toolkit / clipostoolkit / cosmk / completion.py View on Github external
if not os.path.isdir(product_path):
                continue
            _product_path_split = os.path.normpath(product_path).split("/")
            product_name = _product_path_split[-1]
            try:
                product_obj = Product(product_name)
            except Exception as exc:
                exctype = exc.__class__.__name__
                argcomplete.warn(line("""
                    An exception {!r} occured when evaluating product
                    {!r}.""").format(exctype, product_name))
                continue
            products.append(product_name)
    except Exception as exc:
        exctype = exc.__class__.__name__
        argcomplete.warn(line("""
            An exception {!r} occured when enumerating all the available
            products.""").format(exctype))

    return products
github ccbrown / needy / needy / command.py View on Github external
def wrapper(parsed_args, **kwds):
        import argcomplete
        try:
            with cd(parsed_args.C) if getattr(parsed_args, 'C', None) else DummyContextManager() as _:
                return f(parsed_args=parsed_args, **kwds)
        except Exception as e:
            argcomplete.warn('An error occurred during argument completion: {}'.format(e))
    return wrapper
github GoogleCloudPlatform / gsutil / gslib / tab_complete.py View on Github external
timeout: Time limit for the request.
    Returns:
      Cloud resources matching the given wildcard URL.
    Raises:
      TimeoutError: If the listing does not finish within the timeout.
    """
    request_thread = CloudListingRequestThread(wildcard_url, self._gsutil_api)
    request_thread.start()
    request_thread.join(timeout)

    if request_thread.is_alive():
      # This is only safe to import if argcomplete is present in the install
      # (which happens for Cloud SDK installs), so import on usage, not on load.
      # pylint: disable=g-import-not-at-top
      import argcomplete
      argcomplete.warn(_TIMEOUT_WARNING % timeout)
      raise TimeoutError()

    results = request_thread.results

    return results
github chanzuckerberg / miniwdl / WDL / CLI.py View on Github external
def runner_input_completer(prefix, parsed_args, **kwargs):
    # argcomplete completer for `miniwdl run` and `miniwdl cromwell`
    if "uri" in parsed_args:
        # load document. in the completer setting, we need to substitute the home directory
        # and environment variables
        uri = os.path.expandvars(os.path.expanduser(parsed_args.uri))
        if not (uri.startswith("http:") or uri.startswith("https:") or os.path.exists(uri)):
            argcomplete.warn("file not found: " + uri)
            return []
        try:
            doc = load(
                uri,
                path=(parsed_args.path if hasattr(parsed_args, "path") else []),
                check_quant=parsed_args.check_quant,
                read_source=read_source,
            )
        except Exception as exn:
            argcomplete.warn(
                "unable to load {}; try 'miniwdl check' on it ({})".format(uri, str(exn))
            )
            return []
        # resolve target
        if doc.workflow:
            target = doc.workflow
github qmk / qmk_firmware / lib / python / milc.py View on Github external
def initialize_argparse(self):
        """Prepare to process arguments from sys.argv.
        """
        kwargs = {
            'fromfile_prefix_chars': '@',
            'conflict_handler': 'resolve',
        }

        self.acquire_lock()
        self.subcommands = {}
        self.subcommands_default = {}
        self._subparsers = None
        self._subparsers_default = None
        self.argwarn = argcomplete.warn
        self.args = None
        self._arg_defaults = argparse.ArgumentParser(**kwargs)
        self._arg_parser = argparse.ArgumentParser(**kwargs)
        self.set_defaults = self._arg_parser.set_defaults
        self.print_usage = self._arg_parser.print_usage
        self.print_help = self._arg_parser.print_help
        self.release_lock()
github Azure / azure-cli / src / azure-cli / azure / cli / command_modules / acs / _completers.py View on Github external
def _get_location_from_resource_group(cli_ctx, resource_group_name):
    from ._client_factory import cf_resource_groups
    from msrestazure.azure_exceptions import CloudError

    try:
        rg = cf_resource_groups(cli_ctx).get(resource_group_name)
        return rg.location
    except CloudError as err:
        # Print a warning if the user hit [TAB] but the `--resource-group` argument was incorrect.
        # For example: "Warning: Resource group 'bogus' could not be found."
        from argcomplete import warn
        warn('Warning: {}'.format(err.message))
github XiaoMi / galaxy-fds-sdk-python / fds / fds_cmd.py View on Github external
def bucket_name_completer(prefix, parsed_args, **kwargs):
  parse_argument(args=parsed_args)

  if not (access_key is None) and not (secret_key is None) and not (region is None):
    argcomplete.warn(str(enable_https) + ' ' + str(enable_cdn) + ' ' + str(region))
    fds_config = FDSClientConfiguration(region_name=region,
                                        enable_https=enable_https,
                                        enable_cdn_for_download=enable_cdn,
                                        enable_cdn_for_upload=enable_cdn)
    fds_client = GalaxyFDSClient(access_key=access_key,
                                 access_secret=secret_key,
                                 config=fds_config)
    bucket_list = get_buckets(fds_client=fds_client)
    rtn = []
    for i in bucket_list:
      if i.startswith(prefix):
        rtn.append(i)
    return rtn
  return ['a', 'b', 'c']
github XiaoMi / galaxy-fds-sdk-python / fds / fds_cli.py View on Github external
def bucket_name_completer(prefix, parsed_args, **kwargs):
  parse_argument(args=parsed_args)

  if not (access_key is None) and not (secret_key is None) and not (region is None):
    argcomplete.warn(str(enable_https) + ' ' + str(enable_cdn) + ' ' + str(region))
    fds_config = FDSClientConfiguration(region_name=region,
                                        enable_https=enable_https,
                                        enable_cdn_for_download=enable_cdn,
                                        enable_cdn_for_upload=enable_cdn)
    fds_client = GalaxyFDSClient(access_key=access_key,
                                 access_secret=secret_key,
                                 config=fds_config)
    bucket_list = get_buckets(fds_client=fds_client)
    rtn = []
    for i in bucket_list:
      if i.startswith(prefix):
        rtn.append(i)
    return rtn
  return ['a', 'b', 'c']