First CLI command: sqlite-utils table_names test.db

This commit is contained in:
Simon Willison 2019-01-24 19:30:47 -08:00
commit fd5829b27d
4 changed files with 60 additions and 3 deletions

View file

@ -1,6 +1,22 @@
import click
import sqlite_utils
@click.command()
def cli(*args):
click.echo(repr(args))
@click.group()
@click.version_option()
def cli():
"Commands for interacting with a SQLite database"
pass
@cli.command()
@click.argument(
"path",
type=click.Path(exists=True, file_okay=True, dir_okay=False, allow_dash=False),
required=True,
)
def table_names(path):
"""List the tables in the database"""
db = sqlite_utils.Database(path)
for name in db.table_names:
print(name)