Skip to main content

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 Command class
  • 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

foxcli-0.2.0.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

foxcli-0.2.0-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

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

Hashes for foxcli-0.2.0.tar.gz
Algorithm Hash digest
SHA256 559d18f2feb8bcbcd66646909b3d82c5dad88bcf6fb19d2324fb422cf2c0c664
MD5 aa2d0f95886b8bfa4ca118d6e17ad74c
BLAKE2b-256 40eeabbf7402a234aeecea7e40981e8e1b1648f3ead97b19ff472478537414bf

See more details on using hashes here.

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

Hashes for foxcli-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ba203d0ae989a635f926faf2eb9e19f6e80e9d0fa3f4bb8b301ffc3bf9bd637b
MD5 68481dc43d4297520273583111cb497a
BLAKE2b-256 54c67de4d19fbc375bd9115b1c1a2768872d9fa21cf8a1906efc4da7d62924b9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page