This file is indexed.

/usr/lib/python3/dist-packages/cement/ext/ext_argcomplete.py is in python3-cement 2.10.0-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
"""
The Argcomplete Extension provides the necessary hooks to utilize
the `Argcomplete Library <https://argcomplete.readthedocs.io/en/latest/>`_,
and perform auto-completion of command line arguments/options/sub-parsers/etc.

Requirements
------------

 * Argcomplete (``pip install argcomplete``)
 * Argparse


This extension currently only works when using
:class:`cement.ext.ext_argparse.ArgparseArgumentHandler` (default) and
:class:`cement.ext.ext_argparse.ArgparseController` (new in Cement 2.8).  It
will not work with :class:`cement.core.controller.CementBaseController`.


Configuration
-------------

This extension does not honor any application configuration settings.


Usage
-----

**myapp.py**

.. code-block:: python

    #!/usr/bin/env python

    from cement.core.foundation import CementApp
    from cement.ext.ext_argparse import ArgparseController, expose


    class BaseController(ArgparseController):
        class Meta:
            label = 'base'
            arguments = [
                (['-f', '--foo'], dict(help='base foo option', dest='foo'))
            ]

        @expose(hide=True)
        def default(self):
            print('Inside BaseController.default')

        @expose()
        def command1(self):
            print('Inside BaseController.command1')


    class MyApp(CementApp):
        class Meta:
            label = 'myapp'
            extensions = ['argcomplete']
            handlers = [BaseController]

    with MyApp() as app:
        app.run()


Note the ``#!`` line, which allows us to call our script directly
(specifically for this example).  The Argcomplete library requires the
end-user to modify their environment in order to perform auto-completion.
For this example, we are using a non-global option for demonstration
purposes only.  In the *real world* you will need to setup Argcomplete for
your actual application entry-point name (i.e. ``myapp`` if installed as
``/usr/bin/myapp``, etc).

.. code-block:: console

    $ eval "$(register-python-argcomplete myapp.py)"

    $ ./myapp.py [tab][tab]

    --debug                              -h
    -o                                   --help
    --quiet                              command1
                                         default

See the
`Argcomplete Documentation <https://argcomplete.readthedocs.io/en/latest/>`_
on how to properly integrate it's usage into your application deployment.
This extension simply enables Argcomplete to do it's thing on application
startup.

"""

import argcomplete


def argparse_autocompletion(app):
    # Argcomplete doesn't support hidden options currently, so lets atleast
    # exclude our special options in ArgparseController
    exclude = []
    if hasattr(app, 'controller') and app.controller is not None:
        if hasattr(app.controller, '_dispatch_option'):
            exclude.append(app.controller._dispatch_option)
        if hasattr(app.controller, '_controller_option'):
            exclude.append(app.controller._controller_option)

    argcomplete.autocomplete(app.args, exclude=exclude)


def load(app):
    app.hook.register('pre_argument_parsing',
                      argparse_autocompletion, weight=99)