Skip to content

Instantly share code, notes, and snippets.

Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@wabiloo
wabiloo / rest_api_commands.py
Last active March 21, 2023 22:55
Python click experiments for REST API wrapper
import click
class RestEndpointGroup(click.Group):
"""A click.Group sub-class that enables the use of command lines that
1. mirror REST endpoint structure
(eg. `mycli sources 123 slots 456` -> http://myapi/sources/:source_id/slots/:slot_id)
2. allow for implicit commands for `list` and `get` when no sub-commands are provided
on parent groups that support it.
(eg. `mycli sources` -> `mycli sources list`)