Skip to content
This repository has been archived by the owner on Nov 16, 2024. It is now read-only.

Commit

Permalink
move cli init before db
Browse files Browse the repository at this point in the history
  • Loading branch information
eccentricOrange authored Jun 3, 2022
1 parent bcbe18d commit a3f7508
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
12 changes: 6 additions & 6 deletions npbc_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ def getlogs(parsed_arguments: ArgNamespace, connection: Connection) -> None:
print(', '.join(str(item) for item in row))


def update(parsed_arguments: ArgNamespace) -> None:
def update(parsed_arguments: ArgNamespace, _: Connection) -> None:
"""update the application
- under normal operation, this function should never run
- if the update CLI argument is provided, this script will never run and the updater will be run instead"""
Expand All @@ -701,9 +701,12 @@ def update(parsed_arguments: ArgNamespace) -> None:

def main(arguments: list[str]) -> None:
"""main function
- initialize the database
- parses the command line arguments
- initialize the database
- calls the appropriate function based on the arguments"""

# parse the command line arguments
parsed_namespace = define_and_read_args(arguments)

# attempt to initialize the database
try:
Expand All @@ -713,13 +716,10 @@ def main(arguments: list[str]) -> None:
except DatabaseError as e:
status_print(False, f"Database error: {e}\nPlease report this to the developer.")
return

# parse the command line arguments
parsed_namespace = define_and_read_args(arguments)

try:

with connect(database_path) as connection:

# execute the appropriate function
parsed_namespace.func(parsed_namespace, connection)

Expand Down
3 changes: 1 addition & 2 deletions test_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ def test_db_creation():
DATABASE_PATH.unlink(missing_ok=True)
assert not DATABASE_PATH.exists()

with raises(SystemExit):
npbc_cli.main([])
npbc_cli.main(['update'])

assert DATABASE_PATH.exists()

Expand Down

0 comments on commit a3f7508

Please sign in to comment.