cli-todo-jd 0.2.0__py3-none-any.whl → 0.2.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
cli_todo_jd/cli_entry.py CHANGED
@@ -37,8 +37,43 @@ def add(
37
37
  @app.command(name="list")
38
38
  def list_(
39
39
  filepath: Path = typer.Option(Path(".todo_list.db"), "--filepath", "-f"),
40
+ show_all: bool = typer.Option(
41
+ False, "--all", "-a", help="Show all todos (open + done)."
42
+ ),
43
+ show_done: bool = typer.Option(
44
+ False, "--done", "-d", help="Show only completed todos."
45
+ ),
46
+ show_open: bool = typer.Option(
47
+ False, "--open", "-o", help="Show only open todos (default)."
48
+ ),
40
49
  ) -> None:
41
- list_items_on_list(filepath)
50
+ """List todos.
51
+
52
+ Examples
53
+ --------
54
+ - todo list
55
+ - todo list --done
56
+ - todo list --all
57
+ - todo list -a
58
+ """
59
+
60
+ # Choose filter. If nothing specified, default to open.
61
+ # If the user specifies multiple flags, error out.
62
+ flags = [show_all, show_done, show_open]
63
+ if sum(1 for f in flags if f) > 1:
64
+ raise typer.BadParameter(
65
+ "Use only one of: --all / -a, --done / -d, --open / -o"
66
+ )
67
+
68
+ if show_all:
69
+ show = "all"
70
+ elif show_done:
71
+ show = "done"
72
+ else:
73
+ # default is open (or explicit --open)
74
+ show = "open"
75
+
76
+ list_items_on_list(filepath, show=show)
42
77
 
43
78
 
44
79
  @app.command()
@@ -80,7 +115,7 @@ def done(
80
115
  filepath: Path = typer.Option(Path(".todo_list.db"), "--filepath", "-f"),
81
116
  ) -> None:
82
117
  mark_item_as_done(index, filepath)
83
- list_(filepath=filepath)
118
+ list_items_on_list(filepath=filepath, show="all")
84
119
 
85
120
 
86
121
  @app.command()
@@ -89,7 +124,7 @@ def not_done(
89
124
  filepath: Path = typer.Option(Path(".todo_list.db"), "--filepath", "-f"),
90
125
  ) -> None:
91
126
  mark_item_as_not_done(index, filepath)
92
- list_(filepath=filepath)
127
+ list_items_on_list(filepath=filepath, show="all")
93
128
 
94
129
 
95
130
  def parser_optional_args(parser: ArgumentParser):
cli_todo_jd/main.py CHANGED
@@ -45,13 +45,51 @@ class TodoApp:
45
45
  print(f'Added todo: "{item}"')
46
46
  self._check_and_load_todos(self.file_path_to_db)
47
47
 
48
- def list_todos(self) -> None:
48
+ def list_todos(self, *, show: str = "open") -> None:
49
+ """List todos.
50
+
51
+ Parameters
52
+ ----------
53
+ show:
54
+ "open" (default), "done", or "all".
55
+ """
56
+ show = (show or "open").lower()
57
+ if show not in {"open", "done", "all"}:
58
+ print("Error: show must be one of: open, done, all")
59
+ return
60
+
49
61
  # Always read fresh so output reflects the DB
50
62
  self._check_and_load_todos(self.file_path_to_db)
51
63
  if not self.todos:
52
64
  print("No todos found.")
53
65
  return
54
- self._table_print()
66
+
67
+ if show == "all":
68
+ self._table_print(title="Todos")
69
+ return
70
+
71
+ # Filter in-memory to keep this change minimal. (You can later filter in SQL.)
72
+ filtered_todos: list[str] = []
73
+ filtered_status: list[int] = []
74
+ for todo, done in zip(self.todos, self.status, strict=False):
75
+ if show == "open" and not done:
76
+ filtered_todos.append(todo)
77
+ filtered_status.append(done)
78
+ elif show == "done" and done:
79
+ filtered_todos.append(todo)
80
+ filtered_status.append(done)
81
+
82
+ if not filtered_todos:
83
+ print("No todos found.")
84
+ return
85
+
86
+ original_todos, original_status = self.todos, self.status
87
+ try:
88
+ self.todos, self.status = filtered_todos, filtered_status
89
+ title = "Open todos" if show == "open" else "Completed todos"
90
+ self._table_print(title=title)
91
+ finally:
92
+ self.todos, self.status = original_todos, original_status
55
93
 
56
94
  def remove_todo(self, index: int) -> None:
57
95
  # Maintain current UX: index refers to the displayed (1-based) ordering.
@@ -281,7 +319,7 @@ def create_list(file_path_to_db: str = "./.todo_list.db"):
281
319
 
282
320
  Parameters
283
321
  ----------
284
- file_path_to_json : str, optional
322
+ file_path_to_db : str, optional
285
323
  The file path to the JSON file for storing todos, by default "./.todo_list.db"
286
324
 
287
325
  Returns
@@ -309,17 +347,18 @@ def add_item_to_list(item: str, filepath: str):
309
347
  app.list_todos()
310
348
 
311
349
 
312
- def list_items_on_list(filepath: str):
313
- """
314
- List all items in the todo list.
350
+ def list_items_on_list(filepath: str, show: str = "open"):
351
+ """List items in the todo list.
315
352
 
316
353
  Parameters
317
354
  ----------
318
- filepath : str
319
- The file path to the JSON file for storing todos.
355
+ filepath:
356
+ The SQLite database path.
357
+ show:
358
+ "open" (default), "done", or "all".
320
359
  """
321
360
  app = create_list(file_path_to_db=filepath)
322
- app.list_todos()
361
+ app.list_todos(show=show)
323
362
 
324
363
 
325
364
  def remove_item_from_list(index: int, filepath: str):
@@ -388,7 +427,7 @@ def cli_menu(filepath="./.todo_list.db"):
388
427
  item = questionary.text("Enter the todo item:").ask()
389
428
  app.add_todo(item)
390
429
  elif action == "List todos":
391
- app.list_todos()
430
+ app.list_todos(show="all")
392
431
  elif action == "Update todo status":
393
432
  if not app.todos:
394
433
  print("No todos to update.")
@@ -398,7 +437,7 @@ def cli_menu(filepath="./.todo_list.db"):
398
437
  choices=["<Back>"] + app.todos,
399
438
  ).ask()
400
439
 
401
- if todo_choice == "<Back>":
440
+ if todo_choice == "<Back>" or todo_choice is None:
402
441
  continue
403
442
 
404
443
  todo_index = app.todos.index(todo_choice) + 1
@@ -407,13 +446,13 @@ def cli_menu(filepath="./.todo_list.db"):
407
446
  choices=["Done", "Not Done", "<Back>"],
408
447
  ).ask()
409
448
 
410
- if status_choice == "<Back>":
449
+ if status_choice == "<Back>" or status_choice is None:
411
450
  continue
412
451
  elif status_choice == "Done":
413
452
  app.mark_as_done(todo_index)
414
453
  elif status_choice == "Not Done":
415
454
  app.mark_as_not_done(todo_index)
416
- app.list_todos()
455
+ app.list_todos(show="all")
417
456
  elif action == "Remove todo":
418
457
  if not app.todos:
419
458
  print("No todos to remove.")
@@ -423,7 +462,7 @@ def cli_menu(filepath="./.todo_list.db"):
423
462
  choices=["<Back>"] + app.todos,
424
463
  ).ask()
425
464
 
426
- if todo_choice == "<Back>":
465
+ if todo_choice == "<Back>" or todo_choice is None:
427
466
  continue
428
467
 
429
468
  todo_to_remove = app.todos.index(todo_choice) + 1
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cli-todo-jd
3
- Version: 0.2.0
3
+ Version: 0.2.1
4
4
  Summary: Add your description here
5
5
  Requires-Python: >=3.10
6
6
  Description-Content-Type: text/markdown
@@ -0,0 +1,11 @@
1
+ cli_todo_jd/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ cli_todo_jd/cli_entry.py,sha256=PiwgYwT5OTvY0ZyPIxEjBrvdNgEQzx5awgqcKXh1AUE,3875
3
+ cli_todo_jd/main.py,sha256=cqjwHSg4l0aH4aLHyVxOHW8WlRiXp0dB4s8PjhIRxao,15437
4
+ cli_todo_jd/storage/__init__.py,sha256=u0jMfDuUIEy9mor1dVeIiAE0Cap6FL77tW9GlsyskYU,210
5
+ cli_todo_jd/storage/migrate.py,sha256=Ij_0OwTvibow79KVilf2O2nfMuohj0raarVV7OcjwbY,3063
6
+ cli_todo_jd/storage/schema.py,sha256=r5BTtcRn8J72_b8NJlryYnd_aiuy0y00eX01QavKE98,1824
7
+ cli_todo_jd-0.2.1.dist-info/METADATA,sha256=YGHa7H0kv4b8aoNPBj_lgKcF6TMyoiDUGhWEhjbKCkY,2982
8
+ cli_todo_jd-0.2.1.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
9
+ cli_todo_jd-0.2.1.dist-info/entry_points.txt,sha256=BIfrMKcC340A79aXHg34nnhiDsXh7c9hPck1k-Rb28c,95
10
+ cli_todo_jd-0.2.1.dist-info/top_level.txt,sha256=hOnYr7w1JdQs6MlD1Uzjt24Ca8nvriOWNNq6NaqgHqM,12
11
+ cli_todo_jd-0.2.1.dist-info/RECORD,,
@@ -1,11 +0,0 @@
1
- cli_todo_jd/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- cli_todo_jd/cli_entry.py,sha256=sKp-aIWVldH8DiXv22bokjlIiJcAZshKHdLEqjM09HA,2877
3
- cli_todo_jd/main.py,sha256=AN22ojW0iIXArJQmtEjQ1jSdAb7Z-xr8i4NIEE4xAQ0,13965
4
- cli_todo_jd/storage/__init__.py,sha256=u0jMfDuUIEy9mor1dVeIiAE0Cap6FL77tW9GlsyskYU,210
5
- cli_todo_jd/storage/migrate.py,sha256=Ij_0OwTvibow79KVilf2O2nfMuohj0raarVV7OcjwbY,3063
6
- cli_todo_jd/storage/schema.py,sha256=r5BTtcRn8J72_b8NJlryYnd_aiuy0y00eX01QavKE98,1824
7
- cli_todo_jd-0.2.0.dist-info/METADATA,sha256=rra5GQZYrK8xCKX3pUaW0wnmw_pujlKR8bpOIVH-a1U,2982
8
- cli_todo_jd-0.2.0.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
9
- cli_todo_jd-0.2.0.dist-info/entry_points.txt,sha256=BIfrMKcC340A79aXHg34nnhiDsXh7c9hPck1k-Rb28c,95
10
- cli_todo_jd-0.2.0.dist-info/top_level.txt,sha256=hOnYr7w1JdQs6MlD1Uzjt24Ca8nvriOWNNq6NaqgHqM,12
11
- cli_todo_jd-0.2.0.dist-info/RECORD,,