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 .

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.

Release History

See GitHub Releases.

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.0.tar.gz (43.7 kB view details)

Uploaded Source

Built Distribution

knack-0.3.0-py2.py3-none-any.whl (62.2 kB view details)

Uploaded Python 2 Python 3

File details

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

File metadata

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

File hashes

Hashes for knack-0.3.0.tar.gz
Algorithm Hash digest
SHA256 bb57d817fc68e3fc26f28633f583477eba73c26cc8fb2438d7aaf7aee5a2162d
MD5 cd06336503a7f121406b7cbe24c34547
BLAKE2b-256 f3a83661c3be49473256dc428ba4278b4552f414e615c4dc0b318c7eedb9e1fa

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for knack-0.3.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 67f92ffe0eecd3d4022aaa9908e11eb21cd8289570be914ac7d01575b378940a
MD5 25eb9bf1027a6e50c065ab3ed88b6aba
BLAKE2b-256 02551504e0f7810e3a7bc60635faba19c3279ec5925de946dd1148ef5296fe4b

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