Skip to content

Commit f25e849

Browse files
committed
Improve CLI usability, update help, and reach 100% test coverage
- Default CLI to show current task when no command is given - Update CLI help message to reflect default behavior - Add automated test for CLI default behavior - Exclude setup.py from coverage measurement - Achieve 100% test coverage on application code
1 parent 9eea7fa commit f25e849

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

.coveragerc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ omit =
55
*/test_*.py
66
*/__pycache__/*
77
*/site-packages/*
8+
setup.py
89

910
[report]
1011
exclude_lines =

main.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,11 @@ def reopen_task(self, task_id: int) -> None:
151151

152152
def main() -> None:
153153
"""Handle CLI commands and execute appropriate actions."""
154-
parser = argparse.ArgumentParser(description='TaskNow - Minimalist Task Manager')
155-
subparsers = parser.add_subparsers(dest='command', required=True)
154+
parser = argparse.ArgumentParser(
155+
description='TaskNow - Minimalist Task Manager',
156+
epilog='If no command is provided, defaults to showing the current task.'
157+
)
158+
subparsers = parser.add_subparsers(dest='command')
156159

157160
# Show current task
158161
subparsers.add_parser('show', help='Show current task')
@@ -184,6 +187,8 @@ def main() -> None:
184187
edit_parser.add_argument('new_description', nargs='*', help='New task description')
185188

186189
args = parser.parse_args()
190+
if args.command is None:
191+
args.command = 'show'
187192
manager = TaskManager()
188193

189194
try:

test_main.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,4 +350,23 @@ def test_cli_exception_handling(capsys):
350350

351351
captured = capsys.readouterr()
352352
combined_output = captured.out + captured.err
353-
assert "Error: Simulated error" in combined_output
353+
assert "Error: Simulated error" in combined_output
354+
355+
356+
def test_cli_default_to_show(capsys, tmp_path):
357+
"""Test CLI defaults to showing current task when no command is given."""
358+
# Patch TASKS_FILE to use a temp file
359+
temp_file = tmp_path / "tasks.json"
360+
with patch('main.TASKS_FILE', str(temp_file)):
361+
from main import TaskManager, main as cli_main
362+
363+
# Add a task so there is something to show
364+
manager = TaskManager()
365+
manager.add_task("Default show task")
366+
367+
# Simulate running CLI with no arguments
368+
with patch('sys.argv', ['main.py']):
369+
cli_main()
370+
371+
captured = capsys.readouterr()
372+
assert "Current task: Default show task" in captured.out

0 commit comments

Comments
 (0)