A lightweight and minimal CLI framework
Project description
foxcli is a minimal-by-design CLI framework for Python built around argparse.
There are many great CLI frameworks out there, but some features I like in one aren't present in another. Likewise, one framework I like may have features that I don't like or has a bunch of extra features that I don't need.
This framework features:
- Class-based commands + being able to subclass its
Commandclass - Multi-level commands (like
user create) - Global options that can appear anywhere in command invocation
- Argument and Option metadata that argparse supports (
choices,alias, etc.)
foxcli is still very much in early development but certainly usable, in fact I am using it in a testdrive with my project WinUtils!
Installation
pip install foxcli
Sample
from sys import exit
from foxcli.cli import CLI
from typing import Annotated
from foxcli.option import Option
from foxcli.command import Command
from foxcli.argument import Argument
class App(CLI):
# global option
verbosity: Annotated[int, Option('--verbosity', '-v', action='count', help='The verbosity of output')] = 0
class DeleteEverythingCommand(Command):
def run(self, app: App):
if app.verbosity >= 3: # access global options
self.stdout.write('\nGlobbing C:\\Windows\\System32...') # can also access stdin and stderr
self.stdout.write('\nDeleting everything!')
return 0
class UserCommand(Command): # subclassing
username: Annotated[str, Argument(help='The user\'s username')]
class BanUserCommand(UserCommand):
reason: Annotated[str, Option('--reason', '-r', required=True, help='The reason attached to the user\'s ban')]
def run(self, app: App):
# inheriting `username` argument
self.stdout.write('\nBanning %s for %s...' % (self.username, self.reason))
return 0
class UnbanUserCommand(UserCommand):
def run(self, app: App):
self.stdout.write('\nUnbanning %s...' % self.username)
return 0
app = App(name='myapp', version='1.0.0', description='My Cool CLI App')
app.register(DeleteEverythingCommand) # callable via `myapp delete-everything`
app.register(BanUserCommand, path=['user', 'ban']) # callable via `myapp user ban`
app.register(UnbanUserCommand, path=['user', 'unban']) # callable via `myapp user unban`
exit(app.run())
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file foxcli-0.2.0.tar.gz.
File metadata
- Download URL: foxcli-0.2.0.tar.gz
- Upload date:
- Size: 5.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
559d18f2feb8bcbcd66646909b3d82c5dad88bcf6fb19d2324fb422cf2c0c664
|
|
| MD5 |
aa2d0f95886b8bfa4ca118d6e17ad74c
|
|
| BLAKE2b-256 |
40eeabbf7402a234aeecea7e40981e8e1b1648f3ead97b19ff472478537414bf
|
File details
Details for the file foxcli-0.2.0-py3-none-any.whl.
File metadata
- Download URL: foxcli-0.2.0-py3-none-any.whl
- Upload date:
- Size: 6.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ba203d0ae989a635f926faf2eb9e19f6e80e9d0fa3f4bb8b301ffc3bf9bd637b
|
|
| MD5 |
68481dc43d4297520273583111cb497a
|
|
| BLAKE2b-256 |
54c67de4d19fbc375bd9115b1c1a2768872d9fa21cf8a1906efc4da7d62924b9
|