A Command-Line Interface framework
Project description
Knack
_ _ | | ___ __ __ _ ___| | __ | |/ / '_ \ / _` |/ __| |/ / | <| | | | (_| | (__| < |_|\_\_| |_|\__,_|\___|_|\_\
A Command-Line Interface framework
Installation is easy via pip:
pip install knack
Knack can be installed as a non-privileged user to your home directory by adding “–user” as below:
pip install knack --user
Usage
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.
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.12.0.tar.gz
.
File metadata
- Download URL: knack-0.12.0.tar.gz
- Upload date:
- Size: 72.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: RestSharp/106.13.0.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 71f2a6b42ae9a302e43243320fa05edb09b19339fcf1f331f5b6d07bf97f5291 |
|
MD5 | 98147c289ce970041479d41992d35fc0 |
|
BLAKE2b-256 | bbeb1f26c9112a4ee84cfa4a0a81bdf844207496a476fa026cfc98545bb702db |
File details
Details for the file knack-0.12.0-py3-none-any.whl
.
File metadata
- Download URL: knack-0.12.0-py3-none-any.whl
- Upload date:
- Size: 60.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: RestSharp/106.13.0.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c1c3e8555f5aa974880f580ad7c862502b6ef274b1c9891ae0cc17f8eaa5c8b5 |
|
MD5 | 30bda4cb6a4308ffd1bdcfbcc7f04849 |
|
BLAKE2b-256 | 2928dc87d6014ad6dbfeaf0ee79e62d225ae80f537dade0ac690d67b11e2c948 |