simonw / sqlite-utils

Python CLI utility and library for manipulating SQLite databases
https://sqlite-utils.datasette.io
Apache License 2.0
1.62k stars 109 forks source link

register_command plugin hook #569

Closed simonw closed 1 year ago

simonw commented 1 year ago

I'm going to start by adding the register_command hook using the exact same pattern as Datasette and LLM.

Originally posted by @simonw in https://github.com/simonw/sqlite-utils/issues/567#issuecomment-1646643450

simonw commented 1 year ago

Here's where I added that to LLM: https://github.com/simonw/llm/commit/a396950f7934e82a9968703bb3ce9ab7ab62f7f8

simonw commented 1 year ago

Example plugin: https://gist.github.com/simonw/ccfbbf9b384a38ac7535b01849f57daf

sqlite-utils install https://gist.github.com/simonw/ccfbbf9b384a38ac7535b01849f57daf/archive/cd7960e476c441a3c5f619e2a44a641a39b91467.zip

pyproject.toml:

[project]
name = "sqlite-utils-hello-world"
version = "0.1"

[project.entry-points.sqlite_utils]
hello_world = "sqlite_utils_hello_world"

sqlite_utils_hello_world.py:

import click
import sqlite_utils

@sqlite_utils.hookimpl
def register_commands(cli):
    @cli.command()
    def hello_world():
        "Say hello world"
        click.echo("Hello world!")
simonw commented 1 year ago

Documentation: https://sqlite-utils.datasette.io/en/latest/plugins.html#register-commands-cli