File: README.rst

package info (click to toggle)
python-click-didyoumean 0.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 88 kB
  • sloc: python: 169; makefile: 6
file content (132 lines) | stat: -rw-r--r-- 3,140 bytes parent folder | download
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
click-didyoumean
================
|pypi| |build| |license|

Enable git-like *did-you-mean* feature in click.

It's as simple as this:

.. code:: python

    import click
    from click_didyoumean import DYMGroup

    @click.group(cls=DYMGroup)
    def cli():
        ...

|demo|

Usage
-----

Install this extension with pip:

.. code::

    pip install click-didyoumean


Use specific *did-you-mean* `group` class for your cli:


.. code:: python

    import click
    from click_didyoumean import DYMGroup

    @click.group(cls=DYMGroup)
    def cli():
        pass

    @cli.command()
    def foo():
        pass

    @cli.command()
    def bar():
        pass

    @cli.command()
    def barrr():
        pass

    if __name__ == "__main__":
        cli()


Or you it in a `CommandCollection`:

.. code:: python

    import click
    from click_didyoumean import DYMCommandCollection

    @click.group()
    def cli1():
        pass

    @cli1.command()
    def foo():
        pass

    @cli1.command()
    def bar():
        pass

    @click.group()
    def cli2():
        pass

    @cli2.command()
    def barrr():
        pass

    cli = DYMCommandCollection(sources=[cli1, cli2])

    if __name__ == "__main__":
        cli()


Change configuration
--------------------

There are two configuration for the ``DYMGroup`` and ``DYMCommandCollection``:

+-----------------+-------+---------+---------------------------------------------------------------------------+
| Parameter       | Type  | Default | Description                                                               |
+=================+=======+=========+===========================================================================+
| max_suggestions | int   | 3       | Maximal number of *did-you-mean* suggestions                              |
+-----------------+-------+---------+---------------------------------------------------------------------------+
| cutoff          | float | 0.5     | Possibilities that don’t score at least that similar to word are ignored. |
+-----------------+-------+---------+---------------------------------------------------------------------------+

Examples
~~~~~~~~

.. code:: python

    @cli.group(cls=DYMGroup, max_suggestions=2, cutoff=0.7)
    def cli():
        pass

    ... or ...

    cli = DYMCommandCollection(sources=[cli1, cli2], max_suggestions=2, cutoff=0.7)


.. |pypi| image:: https://img.shields.io/pypi/v/click-didyoumean.svg?style=flat&label=version
    :target: https://pypi.python.org/pypi/click-didyoumean
    :alt: Latest version released on PyPi

.. |build| image:: https://img.shields.io/travis/timofurrer/click-didyoumean/master.svg?style=flat
    :target: http://travis-ci.org/timofurrer/click-didyoumean
    :alt: Build status of the master branch

.. |demo| image:: https://asciinema.org/a/duyr2j5d7w7fhpe7xf71rafgr.png
    :target: https://asciinema.org/a/duyr2j5d7w7fhpe7xf71rafgr
    :alt: Demo

.. |license| image:: https://img.shields.io/badge/license-MIT-blue.svg?style=flat
    :target: https://raw.githubusercontent.com/timofurrer/click-didyoumean/master/LICENSE
    :alt: Package license