knack


Nameknack JSON
Version 0.11.0 PyPI version JSON
download
home_pagehttps://github.com/microsoft/knack
SummaryA Command-Line Interface framework
upload_time2023-07-26 06:23:32
maintainer
docs_urlNone
authorMicrosoft Corporation
requires_python
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage No coveralls.
            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://dev.azure.com/azure-sdk/public/_apis/build/status/cli/microsoft.knack?branchName=dev
    :target: https://dev.azure.com/azure-sdk/public/_build/latest?definitionId=1643&branchName=dev


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


::

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


**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/dev/examples>`__.


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

Documentation is available at `docs <https://github.com/Microsoft/knack/tree/dev/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>`__.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/microsoft/knack",
    "name": "knack",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "Microsoft Corporation",
    "author_email": "azpycli@microsoft.com",
    "download_url": "https://files.pythonhosted.org/packages/0c/5b/7cc69b2941a11bdace4faffef8f023543feefd14ab0222b6e62a318c53b9/knack-0.11.0.tar.gz",
    "platform": null,
    "description": "Knack\n=====\n\n.. image:: https://img.shields.io/pypi/v/knack.svg\n    :target: https://pypi.python.org/pypi/knack\n\n.. image:: https://img.shields.io/pypi/pyversions/knack.svg\n    :target: https://pypi.python.org/pypi/knack\n\n.. image:: https://dev.azure.com/azure-sdk/public/_apis/build/status/cli/microsoft.knack?branchName=dev\n    :target: https://dev.azure.com/azure-sdk/public/_build/latest?definitionId=1643&branchName=dev\n\n\n------------\n\n\n::\n\n    _                     _\n   | | ___ __   __ _  ___| | __\n   | |/ / '_ \\ / _` |/ __| |/ /\n   |   <| | | | (_| | (__|   <\n   |_|\\_\\_| |_|\\__,_|\\___|_|\\_\\\n\n\n**A Command-Line Interface framework**\n\nInstallation is easy via pip:\n\n.. code-block:: bash\n\n    pip install knack\n\nKnack can be installed as a non-privileged user to your home directory by adding \"--user\" as below:\n\n.. code-block:: bash\n\n    pip install knack --user\n\n------------\n\n.. 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.\n\n------------\n\n\nUsage\n=====\n\n\n.. code-block:: python\n\n    import sys\n    from collections import OrderedDict\n\n    from knack import CLI, ArgumentsContext, CLICommandsLoader\n    from knack.commands import CommandGroup\n\n\n    def abc_str(length=3):\n        import string\n        return string.ascii_lowercase[:length]\n\n\n    class MyCommandsLoader(CLICommandsLoader):\n        def load_command_table(self, args):\n            with CommandGroup(self, 'abc', '__main__#{}') as g:\n                g.command('str', 'abc_str')\n            return OrderedDict(self.command_table)\n\n        def load_arguments(self, command):\n            with ArgumentsContext(self, 'abc str') as ac:\n                ac.argument('length', type=int)\n            super(MyCommandsLoader, self).load_arguments(command)\n\n\n    mycli = CLI(cli_name='mycli', commands_loader_cls=MyCommandsLoader)\n    exit_code = mycli.invoke(sys.argv[1:])\n    sys.exit(exit_code)\n\n    # $ python mycli.py abc str\n    # \"abc\"\n\n    # $ python mycli.py abc str --length 5\n    # \"abcde\"\n\n    # $ python mycli.py abc str --length 100\n    # \"abcdefghijklmnopqrstuvwxyz\"\n\n\nMore samples and snippets are available at `examples <https://github.com/Microsoft/knack/tree/dev/examples>`__.\n\n\nDocumentation\n=============\n\nDocumentation is available at `docs <https://github.com/Microsoft/knack/tree/dev/docs>`__.\n\nDeveloper Setup\n===============\n\nIn a virtual environment, install the `requirements.txt` file.\n\n.. code-block:: bash\n\n    pip install -r requirements.txt\n    pip install -e .\n\nRun Automation\n==============\n\nThis project supports running automation using `tox <https://tox.readthedocs.io/en/latest/>`__.\n\n.. code-block:: bash\n\n    pip install tox\n    tox\n\n\nReal-world uses\n===============\n\n- `Azure CLI <https://github.com/Azure/azure-cli/>`__: The Azure CLI 2.0 is Azure's new command line experience for managing Azure resources.\n- `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.\n- `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.\n\nDo 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.\n\n\nRelease History\n===============\n\nSee `GitHub Releases <https://github.com/Microsoft/knack/releases>`__.\n\n\nContribute Code\n===============\n\nThis project has adopted the `Microsoft Open Source Code of Conduct <https://opensource.microsoft.com/codeofconduct/>`__.\n\nFor 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.\n\nIf you would like to become an active contributor to this project, please\nfollow the instructions provided in `Contribution License Agreement <https://cla.microsoft.com/>`__.\n\n\nLicense\n=======\n\nKnack is licensed under `MIT <LICENSE>`__.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A Command-Line Interface framework",
    "version": "0.11.0",
    "project_urls": {
        "Homepage": "https://github.com/microsoft/knack"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "536bcaf27d5a40618c7e945a1c68e1961c2d3637edfce9ebb0edc27c9ff53c1c",
                "md5": "d7adc27f14a7c9ed4d2ef36269db6e9c",
                "sha256": "6704c867840978a119a193914a90e2e98c7be7dff764c8fcd8a2286c5a978d00"
            },
            "downloads": -1,
            "filename": "knack-0.11.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "d7adc27f14a7c9ed4d2ef36269db6e9c",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 60848,
            "upload_time": "2023-07-26T06:23:30",
            "upload_time_iso_8601": "2023-07-26T06:23:30.221965Z",
            "url": "https://files.pythonhosted.org/packages/53/6b/caf27d5a40618c7e945a1c68e1961c2d3637edfce9ebb0edc27c9ff53c1c/knack-0.11.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0c5b7cc69b2941a11bdace4faffef8f023543feefd14ab0222b6e62a318c53b9",
                "md5": "1f07bcba2dc081acad16ea47a204ee1b",
                "sha256": "eb6568001e9110b1b320941431c51033d104cc98cda2254a5c2b09ba569fd494"
            },
            "downloads": -1,
            "filename": "knack-0.11.0.tar.gz",
            "has_sig": false,
            "md5_digest": "1f07bcba2dc081acad16ea47a204ee1b",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 72308,
            "upload_time": "2023-07-26T06:23:32",
            "upload_time_iso_8601": "2023-07-26T06:23:32.339467Z",
            "url": "https://files.pythonhosted.org/packages/0c/5b/7cc69b2941a11bdace4faffef8f023543feefd14ab0222b6e62a318c53b9/knack-0.11.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-07-26 06:23:32",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "microsoft",
    "github_project": "knack",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "tox": true,
    "lcname": "knack"
}
        
Elapsed time: 0.08993s