Skip to content
This repository has been archived by the owner on Feb 3, 2025. It is now read-only.

Commit

Permalink
small refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaya-Sem committed Jul 22, 2024
1 parent bb2365c commit f903e90
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 32 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ src/build
src/build/**
src/dist
src/dist/**
src/commands/**
src/command/**
1 change: 0 additions & 1 deletion src/commands/add.py → src/command/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
@click.group()
def add():
"""Add items to collections"""
pass


@add.command()
Expand Down
File renamed without changes.
1 change: 0 additions & 1 deletion src/commands/create.py → src/command/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
@click.group()
def create():
"""Create items and collections."""
pass


# TODO: named arguments
Expand Down
23 changes: 11 additions & 12 deletions src/commands/delete.py → src/command/delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@
@click.group()
def delete():
"""Delete items and collections."""
pass


# TODO: use print items instead
@delete.command()
@click.argument("id", required=False, type=int)
def item(id):
if id is None:
@click.argument("item_id", required=False, type=int)
def item(item_id):
if item_id is None:
items = get_items()
if items:
print(f"{len(items)} available items:")
Expand All @@ -24,18 +23,18 @@ def item(id):
print("No items found in the database.")
sys.exit()

id = click.prompt("Enter the ID of the item you want to delete", type=int)
item_id = click.prompt("Enter the ID of the item you want to delete", type=int)

try:
delete_item(id)
delete_item(item_id)
except ValueError as e:
click.echo(str(e))


@delete.command()
@click.argument("id", required=False, type=int)
def collection(id):
if id is None:
@click.argument("collection_id", required=False, type=int)
def collection(collection_id):
if collection_id is None:
collections = get_collections()
if collections:
print(f"{len(collections)} available collections:")
Expand All @@ -45,10 +44,10 @@ def collection(id):
print("\nNo collections found in the database.\n")
sys.exit()

id = click.prompt("Enter the ID of the collection you want to delete", type=int)
collection_id = click.prompt("Enter the ID of the collection you want to delete", type=int)

try:
delete_collection(id)
rich.print(f"\n[green]Collection with ID {id} was succesfully removed[/green]\n")
delete_collection(collection_id)
rich.print(f"\n[green]Collection with ID {collection_id} was succesfully removed[/green]\n")
except ValueError as e:
click.echo(str(e))
1 change: 0 additions & 1 deletion src/commands/list.py → src/command/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
@click.group()
def list():
"""List items, collections and categories"""
pass


@list.command()
Expand Down
1 change: 0 additions & 1 deletion src/commands/remove.py → src/command/remove.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
@click.group()
def remove():
"""Remove items from collections"""
pass


@remove.command()
Expand Down
11 changes: 5 additions & 6 deletions src/commands/view.py → src/command/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,23 @@
@click.group()
def view():
"""View items and collections."""
pass


@view.command()
@click.argument("id", required=False, type=int)
def collection(id):
if id is None:
@click.argument("collection_id", required=False, type=int)
def collection(collection_id):
if collection_id is None:
collections = get_collections()
if collections:
rich.print(f"\nAvailable collections [dim]({len(collections)})[/dim]:\n")
print_collections(collections)
else:
click.echo("No collections found in the database")

id = click.prompt("Enter the ID of the collection you want to view", type=int)
collection_id = click.prompt("Enter the ID of the collection you want to view", type=int)

try:
col: Collection = get_collection(id)
col: Collection = get_collection(collection_id)
print_collection_view(col)
except ValueError as e:
click.echo(str(e))
Expand Down
2 changes: 1 addition & 1 deletion src/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def add_items_to_collection(collection_id: int, item_ids: List[int]):
def delete_item(item_id: int):
conn = Connection(DATABASE)

# TODO: items should not be removed, rather 'archived'
# TODO[#13]: items should not be removed, rather 'archived'
# remove item from collections
conn.cursor.execute(
"DELETE FROM collection_items WHERE item_id = ?", (item_id,)
Expand Down
16 changes: 8 additions & 8 deletions src/main.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import click

from commands.add import add
from commands.checklist import checklist
from commands.list import list
from commands.remove import remove
from commands.view import view
from commands.create import create
from commands.delete import delete
from command.add import add
from command.checklist import checklist
from command.list import list
from command.remove import remove
from command.view import view
from command.create import create
from command.delete import delete


@click.group()
def cli():
pass


# Register commands from commands directory
# Register command from command directory
cli.add_command(checklist)
cli.add_command(add)
cli.add_command(remove)
Expand Down

0 comments on commit f903e90

Please sign in to comment.