-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.py
47 lines (34 loc) · 1.43 KB
/
cli.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import click
from racedb import RaceDB
@click.group()
def cli():
"""This is a user interface to interact with a race database and output json."""
@cli.command("add")
@click.option("--filename", help="Which data file to use.")
def interact_with_db(filename):
RaceDB(filename).prompt()
@cli.command("list")
@click.option("--filename", default=None, help="Which data file to use.")
@click.option("-s", "--search", default='', help="Filter list by search.", type=click.STRING)
def list_db(filename, search):
RaceDB(filename).list(search)
@cli.command("edit")
@click.option("--filename", default=None, help="Which data file to use.")
@click.option("--race-id",
required=True, help="Race id to edit. Use 'list' to view ids.", type=click.INT)
def edit_db(filename, race_id):
RaceDB(filename).update_prompt(race_id)
@cli.command("view")
@click.option("--filename", default=None, help="Which data file to use.")
@click.option("--race-id",
required=True, help="Race id to view. Use 'list' to view ids.", type=click.INT)
def view_db(filename, race_id):
race_id = int(race_id)
db = RaceDB(filename)
db.print_race(db.read(race_id))
@cli.command("copy")
@click.option("--filename", default=None, help="Which data file to use.")
@click.option("-d", "--dest",
required=True, help="Where to copy the race data to", type=click.Path())
def copy_db(filename, dest):
RaceDB(filename).copy(dest)