diff --git a/tests/test_cli_commands.py b/tests/test_cli_commands.py index f6a041d..be96603 100644 --- a/tests/test_cli_commands.py +++ b/tests/test_cli_commands.py @@ -66,6 +66,33 @@ def test_new_command_with_all_flags(self): self.assertEqual(args.list, "personal") self.assertEqual(args.reminder, "9:00") + def test_new_command_with_important(self): + """Test 'new' command with -I flag""" + args = self.parser.parse_args(["new", "-I", "buy milk"]) + self.assertEqual(args.task_name, "buy milk") + self.assertTrue(args.important) + + def test_new_command_with_important_long(self): + """Test 'new' command with --important flag""" + args = self.parser.parse_args(["new", "--important", "buy milk"]) + self.assertEqual(args.task_name, "buy milk") + self.assertTrue(args.important) + + def test_new_command_without_important(self): + """Test 'new' command defaults important to False""" + args = self.parser.parse_args(["new", "buy milk"]) + self.assertFalse(args.important) + + def test_new_command_with_all_flags_including_important(self): + """Test 'new' command with -l, -r, and -I flags""" + args = self.parser.parse_args( + ["new", "-l", "personal", "-r", "9:00", "-I", "buy milk"] + ) + self.assertEqual(args.task_name, "buy milk") + self.assertEqual(args.list, "personal") + self.assertEqual(args.reminder, "9:00") + self.assertTrue(args.important) + def test_newl_command(self): """Test 'newl' command for creating lists""" args = self.parser.parse_args(["newl", "shopping"]) diff --git a/todocli/cli.py b/todocli/cli.py index bd2f661..0480225 100644 --- a/todocli/cli.py +++ b/todocli/cli.py @@ -70,7 +70,12 @@ def new(args): if reminder_date_time_str is not None: reminder_datetime = parse_datetime(reminder_date_time_str) - wrapper.create_task(name, list_name=task_list, reminder_datetime=reminder_datetime) + wrapper.create_task( + name, + list_name=task_list, + reminder_datetime=reminder_datetime, + important=args.important, + ) def newl(args): @@ -136,6 +141,7 @@ def setup_parser(): subparser = subparsers.add_parser("new", help="Add a new task") subparser.add_argument("task_name", help=helptext_task_name) subparser.add_argument("-r", "--reminder") + subparser.add_argument("-I", "--important", action="store_true") subparser.add_argument( "-l", "--list", diff --git a/todocli/graphapi/wrapper.py b/todocli/graphapi/wrapper.py index bef9372..6c71035 100644 --- a/todocli/graphapi/wrapper.py +++ b/todocli/graphapi/wrapper.py @@ -8,7 +8,7 @@ from typing import Union from todocli.models.todolist import TodoList -from todocli.models.todotask import Task, TaskStatus +from todocli.models.todotask import Task, TaskImportance, TaskStatus from todocli.graphapi.oauth import get_oauth_session from todocli.utils.datetime_util import datetime_to_api_timestamp @@ -91,6 +91,7 @@ def create_task( list_name: str | None = None, list_id: str | None = None, reminder_datetime: datetime | None = None, + important: bool = False, ): assert (list_name is not None) or ( list_id is not None @@ -104,6 +105,7 @@ def create_task( request_body = { "title": task_name, "reminderDateTime": datetime_to_api_timestamp(reminder_datetime), + "importance": TaskImportance.HIGH if important else TaskImportance.NORMAL, } session = get_oauth_session() response = session.post(endpoint, json=request_body)