Extra utils for click library
Project description
ClickUtils
Extra utils for click library
Examples
Loading click groups and commands from filepath or directory
Directory structure
_ cwd
|_ __init__.py (contains code below)
|_ plugins/
|_ group_or_command_folder
|_ *groups (this folder must exists to find click groups or commands)
|_ __init__.py (any click groups or commands will be pulled from this location)
...
import os
import click
from clickutils import click_loader
@click.group()
@click.option('--verbose', '-v', type=bool, is_flag=True, default=False,
help='Print more verbose output')
def cli(verbose: bool):
'''click_plugins'''
click_loader.load(plugins_group, os.path.dirname(os.path.abspath(__file__)), verbose=verbose)
@click.group()
def plugins_group():
'''click_plugins test plugins'''
pass
cli.add_command(plugins_group, name='plugins')
if __name__ == '__main__':
cli()
Same example using decorator
import os
import click
from clickutils import click_loader
@click.group()
def cli(verbose: bool):
'''click_plugins'''
@click_loader.group(os.path.dirname(os.path.abspath(__file__)), name='plugins')
def plugins_group():
'''click_plugins test plugins'''
pass
cli.add_command(plugins_group)
if __name__ == '__main__':
cli()
Early example of ClickViewset
import click
from clickutils.viewsets import AbstractClickViewset, clickmixins
from clickutils.viewsets import AbstractClickViewset, clickmixins
class UserDictViewset(AbstractClickViewset):
Name = 'DictionaryViewset'
Version = '1.0.0'
Viewset = {'users': ['user1', 'user2', 'user3']}
commands = ('list', 'version', 'another_command', 'echo')
hidden_commands = ('echo', )
@clickmixins.command(name='another_command')
def another_command(self):
print('defined another user command that can interact with object (self) which contains Viewset attributes')
"""
overloading convert function in BaseClickViewset;
this is a custom way to add the Viewset into the command class attributes
"""
def convert(self):
if isinstance(self.Viewset, dict):
for key, value in self.Viewset.items():
setattr(self, key, value)
@UserDictViewset(name='test_command2')
def test_command_group2():
"""Test command2 plugin"""
pass
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
clickutils-0.1.6.tar.gz
(8.2 kB
view details)
File details
Details for the file clickutils-0.1.6.tar.gz
.
File metadata
- Download URL: clickutils-0.1.6.tar.gz
- Upload date:
- Size: 8.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.37.0 CPython/3.7.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | acd071c3204719a824c5c86bcce0db50a6f697cd9506bc2145fa5f744271328d |
|
MD5 | ae10d539898acdb7af2b7026f682dd10 |
|
BLAKE2b-256 | e6ffa3c2d8698f314466b199a0345ec34d7dfcaaabe3293f8237ce673db03af4 |