Skip to content

Commit c940f6a

Browse files
committed
Add handling to ensure user initializes the database
1 parent 13e6c33 commit c940f6a

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

link_stacklog/database.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,14 @@ def user_dir():
1717
path.mkdir(exist_ok=True, parents=True)
1818
return path
1919

20-
def get_database() -> sqlite_utils.Database:
20+
def get_database(init=False) -> sqlite_utils.Database:
21+
if not init and not (user_dir() / DATABASE_FILE).exists():
22+
click.echo("Database not found. Run 'link-stacklog init' first.")
23+
raise click.Abort()
2124
return sqlite_utils.Database(user_dir() / DATABASE_FILE)
2225

2326
def init_db():
24-
db = get_database()
27+
db = get_database(init=True)
2528

2629
db["links"].create({
2730
"id": int,

0 commit comments

Comments
 (0)