Skip to main content

A Command-Line Interface framework

Project description

Knack

https://img.shields.io/pypi/v/knack.svg https://img.shields.io/pypi/pyversions/knack.svg https://travis-ci.org/Microsoft/knack.svg?branch=master
 _                     _
| | ___ __   __ _  ___| | __
| |/ / '_ \ / _` |/ __| |/ /
|   <| | | | (_| | (__|   <
|_|\_\_| |_|\__,_|\___|_|\_\

A Command-Line Interface framework

pip install knack


Usage

import sys
from collections import OrderedDict
from knack import CLI, CLICommandsLoader, ArgumentsContext

def abc_list(myarg):
    import string
    return list(string.ascii_lowercase)

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

    def load_arguments(self, command):
        with ArgumentsContext(self, 'abc list') as ac:
            ac.argument('myarg', type=int, default=100)
        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)

More samples and snippets available at examples.

Documentation

Documentation is available at docs.

Developer Setup

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

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

Run Automation

This project supports running automation using tox.

pip install tox
tox

Real-world uses

  • Azure CLI: The Azure CLI 2.0 is Azure’s new command line experience for managing Azure resources.

  • 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: 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.

Contribute Code

This project has adopted the Microsoft Open Source Code of Conduct.

For more information see the Code of Conduct FAQ or contact 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

License

Knack is licensed under MIT.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

knack-0.3.2.tar.gz (31.2 kB view details)

Uploaded Source

Built Distribution

knack-0.3.2-py2.py3-none-any.whl (45.2 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file knack-0.3.2.tar.gz.

File metadata

  • Download URL: knack-0.3.2.tar.gz
  • Upload date:
  • Size: 31.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for knack-0.3.2.tar.gz
Algorithm Hash digest
SHA256 aaf825bf9929edffc7a6f067fde44873666d3cd6e43d9557b060d8c9c3f2af5c
MD5 9abf0599550f6cc141de93379d765257
BLAKE2b-256 96a951328c5ac250f7d51d681102d539369102d2bd1280a4f034a689d81d6f41

See more details on using hashes here.

File details

Details for the file knack-0.3.2-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for knack-0.3.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 736595001d882a94af539ed8c8fa541faad8e01df099214817ec20d1ad682603
MD5 7d4c717c9b07c3729cea0196806b35b7
BLAKE2b-256 dd7c55d96c5aad43ab9947ed0c68a5a29f2b2087e6ae3e783e7e622bd0135b6c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page