A Command-Line Interface framework
Project description
Knack
_ _ | | ___ __ __ _ ___| | __ | |/ / '_ \ / _` |/ __| |/ / | <| | | | (_| | (__| < |_|\_\_| |_|\__,_|\___|_|\_\
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file knack-0.4.3.tar.gz
.
File metadata
- Download URL: knack-0.4.3.tar.gz
- Upload date:
- Size: 35.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.25.0 CPython/3.6.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b84459fbf6c8e1cd2f23afb871496e7450e91473aa262326656c61c98b9b8ab1 |
|
MD5 | 8f0d52a57c3e02dbbc305eafead50d93 |
|
BLAKE2b-256 | 9f368a25906aac45e852b46610fbd5c3eb060e0ab138c1fb9e009d55bacf225b |
File details
Details for the file knack-0.4.3-py2.py3-none-any.whl
.
File metadata
- Download URL: knack-0.4.3-py2.py3-none-any.whl
- Upload date:
- Size: 48.1 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.25.0 CPython/3.6.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a6ea9a732cd34037232df7e9527f136bd820a0e09ce649741c6c30d04255a210 |
|
MD5 | d0e77f96a49bd2816df47894fd7d7b26 |
|
BLAKE2b-256 | 773db83a9fe885b1dd3f33888f9d8875a1b340b8a03daba05c573af99b069f5f |