File: README.rst

package info (click to toggle)
knack 0.6.3-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 636 kB
  • sloc: python: 5,404; makefile: 3
file content (151 lines) | stat: -rw-r--r-- 4,236 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
Knack
=====

.. image:: https://img.shields.io/pypi/v/knack.svg
    :target: https://pypi.python.org/pypi/knack

.. image:: https://img.shields.io/pypi/pyversions/knack.svg
    :target: https://pypi.python.org/pypi/knack

.. image:: https://travis-ci.org/Microsoft/knack.svg?branch=master
    :target: https://travis-ci.org/Microsoft/knack


------------


::

    _                     _
   | | ___ __   __ _  ___| | __
   | |/ / '_ \ / _` |/ __| |/ /
   |   <| | | | (_| | (__|   <
   |_|\_\_| |_|\__,_|\___|_|\_\


**A Command-Line Interface framework**

Installation is easy via pip:

.. code-block:: bash

    pip install knack

Knack can be installed as a non-privileged user to your home directory by adding "--user" as below:

.. code-block:: bash
    
    pip install knack --user

------------

.. note:: The project is in `initial development phase <https://semver.org/#how-should-i-deal-with-revisions-in-the-0yz-initial-development-phase>`__. We recommend pinning to at least a specific minor version when marking **knack** as a dependency in your project.

------------


Usage
=====


.. code-block:: python

    import sys
    from collections import OrderedDict

    from knack import CLI, ArgumentsContext, CLICommandsLoader
    from knack.commands import CommandGroup


    def abc_str(length=3):
        import string
        return string.ascii_lowercase[:length]


    class MyCommandsLoader(CLICommandsLoader):
        def load_command_table(self, args):
            with CommandGroup(self, 'abc', '__main__#{}') as g:
                g.command('str', 'abc_str')
            return OrderedDict(self.command_table)

        def load_arguments(self, command):
            with ArgumentsContext(self, 'abc str') as ac:
                ac.argument('length', type=int)
            super(MyCommandsLoader, self).load_arguments(command)


    mycli = CLI(cli_name='mycli', commands_loader_cls=MyCommandsLoader)
    exit_code = mycli.invoke(sys.argv[1:])
    sys.exit(exit_code)

    # $ python mycli.py abc str
    # "abc"

    # $ python mycli.py abc str --length 5
    # "abcde"

    # $ python mycli.py abc str --length 100
    # "abcdefghijklmnopqrstuvwxyz"


More samples and snippets are available at `examples <https://github.com/Microsoft/knack/tree/master/examples>`__.


Documentation
=============

Documentation is available at `docs <https://github.com/Microsoft/knack/tree/master/docs>`__.

Developer Setup
===============

In a virtual environment, install the `requirements.txt` file.

.. code-block:: bash

    pip install -r requirements.txt
    pip install -e .

Run Automation
==============

This project supports running automation using `tox <https://tox.readthedocs.io/en/latest/>`__.

.. code-block:: bash

    pip install tox
    tox


Real-world uses
===============

- `Azure CLI <https://github.com/Azure/azure-cli/>`__: The Azure CLI 2.0 is Azure's new command line experience for managing Azure resources.
- `VSTS CLI <https://github.com/Microsoft/vsts-cli>`__: A command-line interface for Visual Studio Team Services (VSTS) and Team Foundation Server (TFS). With the VSTS CLI, you can manage and work with resources including pull requests, work items, builds, and more.
- `Service Fabric CLI <https://github.com/Azure/service-fabric-cli>`__: A command-line interface for interacting with Azure Service Fabric clusters and their related entities.

Do you use knack in your CLI as well? Open a pull request to include it here. We would love to have it in our list.


Release History
===============

See `GitHub Releases <https://github.com/Microsoft/knack/releases>`__.


Contribute Code
===============

This project has adopted the `Microsoft Open Source Code of Conduct <https://opensource.microsoft.com/codeofconduct/>`__.

For more information see the `Code of Conduct FAQ <https://opensource.microsoft.com/codeofconduct/faq/>`__ or contact `opencode@microsoft.com <mailto:opencode@microsoft.com>`__ with any additional questions or comments.

If you would like to become an active contributor to this project, please
follow the instructions provided in `Contribution License Agreement <https://cla.microsoft.com/>`__.


License
=======

Knack is licensed under `MIT <LICENSE>`__.