-
Notifications
You must be signed in to change notification settings - Fork 99
New support for subtasks #594
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
f21de0d
7259f6b
be317d4
902b512
3e1d526
5c5a5b9
5c72d46
a3b5e9d
373cdee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,5 +13,6 @@ docs/_build/ | |
| .coverage | ||
| .hypothesis | ||
| *.tmp | ||
| .mypy_cache/ | ||
|
|
||
| todoman/version.py | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,7 +22,8 @@ def test_list_all(tmpdir: py.path.local, runner: CliRunner, create: Callable) -> | |
| "DUE;VALUE=DATE-TIME;TZID=CET:20160102T000000\n" | ||
| "DTSTART:20160101T000000Z\n" | ||
| "PERCENT-COMPLETE:26\n" | ||
| "LOCATION:Wherever\n", | ||
| "LOCATION:Wherever\n" | ||
| "RELATED-TO;RELTYPE=PARENT:123456789\n", | ||
| ) | ||
| result = runner.invoke(cli, ["--porcelain", "list", "--status", "ANY"]) | ||
|
|
||
|
|
@@ -40,6 +41,8 @@ def test_list_all(tmpdir: py.path.local, runner: CliRunner, create: Callable) -> | |
| "percent": 26, | ||
| "priority": 0, | ||
| "recurring": False, | ||
| "related_to": "123456789", | ||
| "related_to_reltype": "PARENT", | ||
| "start": 1451606400, | ||
| "summary": "Do stuff", | ||
| } | ||
|
|
@@ -78,6 +81,8 @@ def test_list_start_date( | |
| "percent": 26, | ||
| "priority": 0, | ||
| "recurring": False, | ||
| "related_to": "", | ||
| "related_to_reltype": "", | ||
|
Comment on lines
+84
to
+85
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should exclude the fields when absent, instead of including empty fields. (same applies to other instances below) |
||
| "start": 1451692800, | ||
| "summary": "Do stuff", | ||
| } | ||
|
|
@@ -114,6 +119,8 @@ def test_list_due_date( | |
| "percent": 26, | ||
| "priority": 0, | ||
| "recurring": False, | ||
| "related_to": "", | ||
| "related_to_reltype": "", | ||
| "start": None, | ||
| "summary": "Do stuff", | ||
| } | ||
|
|
@@ -143,6 +150,8 @@ def test_list_nodue(tmpdir: py.path.local, runner: CliRunner, create: Callable) | |
| "location": "", | ||
| "percent": 12, | ||
| "recurring": False, | ||
| "related_to": "", | ||
| "related_to_reltype": "", | ||
| "priority": 4, | ||
| "start": None, | ||
| "summary": "Do stuff", | ||
|
|
@@ -216,6 +225,8 @@ def test_show(tmpdir: py.path.local, runner: CliRunner, create: Callable) -> Non | |
| "percent": 0, | ||
| "priority": 5, | ||
| "recurring": False, | ||
| "related_to": "", | ||
| "related_to_reltype": "", | ||
| "start": None, | ||
| "summary": "harhar", | ||
| } | ||
|
|
@@ -241,6 +252,8 @@ def test_simple_action(todo_factory: Callable) -> None: | |
| "percent": 0, | ||
| "priority": 0, | ||
| "recurring": False, | ||
| "related_to": "", | ||
| "related_to_reltype": "", | ||
| "start": None, | ||
| "summary": "YARR!", | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -54,7 +54,9 @@ def wrapper(*a, **kw) -> _T: | |
|
|
||
|
|
||
| TODO_ID_MIN = 1 | ||
| with_id_arg = click.argument("id", type=click.IntRange(min=TODO_ID_MIN)) | ||
| CLICK_TYPE_ID = click.IntRange(min=TODO_ID_MIN) | ||
|
|
||
| with_id_arg = click.argument("id", type=CLICK_TYPE_ID) | ||
|
|
||
|
|
||
| def _validate_lists_param( | ||
|
|
@@ -238,6 +240,13 @@ def _todo_property_options(command: Callable) -> Callable: | |
| help="When the task starts.", | ||
| )(command) | ||
|
|
||
| # Merges all different property arguments into one dictionary | ||
| # `todo_properties` argument, so that it can be directly looped through | ||
| # easily for directly setting the `todoman.model.Todo` class attributes | ||
| # from within a command function. | ||
| # | ||
| # The names of the options are the same as the | ||
| # `todoman.model.Todo` class attributes. | ||
| @functools.wraps(command) | ||
| def command_wrap(*a, **kw) -> click.Command: | ||
|
Comment on lines
+243
to
251
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nitpick: this should be a docstring rather than comment. |
||
| kw["todo_properties"] = { | ||
|
|
@@ -284,6 +293,21 @@ def formatter(self) -> formatters.Formatter: | |
| help="Go into interactive mode before saving the task.", | ||
| ) | ||
|
|
||
| _subtask_option = click.option( | ||
| "--subtask-for", | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you think of calling this Code-wise it's a bit more obvious, but I'm not sure how obvious it is for a user interface. |
||
| is_flag=False, | ||
| default=None, | ||
| type=CLICK_TYPE_ID, | ||
| help="Set task to be a subtask for the given id.", | ||
| ) | ||
|
|
||
| _not_subtask_option = click.option( | ||
| "--not-subtask", | ||
| is_flag=True, | ||
| default=False, | ||
| help="Make task no longer be a subtask.", | ||
| ) | ||
|
|
||
|
|
||
| @click.group(invoke_without_command=True) | ||
| @click_log.simple_verbosity_option() | ||
|
|
@@ -423,6 +447,7 @@ def repl(ctx: click.Context) -> None: | |
| ) | ||
| @_todo_property_options | ||
| @_interactive_option | ||
| @_subtask_option | ||
| @pass_ctx | ||
| @catch_errors | ||
| def new( | ||
|
|
@@ -432,6 +457,7 @@ def new( | |
| todo_properties: dict, | ||
| read_description: bool, | ||
| interactive: bool, | ||
| subtask_for: int | None, | ||
| ) -> None: | ||
| """ | ||
| Create a new task with SUMMARY. | ||
|
|
@@ -453,6 +479,11 @@ def new( | |
| setattr(todo, key, value) | ||
| todo.summary = " ".join(summary) | ||
|
|
||
| if subtask_for is not None: | ||
| parent_todo = ctx.db.todo(subtask_for) | ||
| todo.related_to = parent_todo.uid | ||
| todo.related_to_reltype = "PARENT" | ||
|
|
||
| if read_description: | ||
| todo.description = sys.stdin.read() | ||
|
|
||
|
|
@@ -487,6 +518,8 @@ def new( | |
| ) | ||
| @_todo_property_options | ||
| @_interactive_option | ||
| @_subtask_option | ||
| @_not_subtask_option | ||
| @with_id_arg | ||
| @catch_errors | ||
| def edit( | ||
|
|
@@ -496,6 +529,8 @@ def edit( | |
| interactive: bool, | ||
| read_description: bool, | ||
| raw: bool, | ||
| subtask_for: int | None, | ||
| not_subtask: bool, | ||
| ) -> None: | ||
| """ | ||
| Edit the task with id ID. | ||
|
|
@@ -516,6 +551,17 @@ def edit( | |
| changes = True | ||
| todo.description = sys.stdin.read() | ||
|
|
||
| if subtask_for is not None and not_subtask is False: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If |
||
| changes = True | ||
| parent_todo = ctx.db.todo(subtask_for) | ||
| todo.related_to = parent_todo.uid | ||
| todo.related_to_reltype = "PARENT" | ||
|
|
||
| if not_subtask: | ||
| changes = True | ||
| todo.related_to = "" | ||
| todo.related_to_reltype = "" | ||
|
|
||
| if interactive or (not changes and interactive is None): | ||
| ui = TodoEditor(todo, ctx.db.lists(), ctx.ui_formatter) | ||
| ui.edit() | ||
|
|
@@ -528,6 +574,7 @@ def edit( | |
| ctx.db.save(todo) | ||
| if old_list != new_list: | ||
| ctx.db.move(todo, new_list=new_list, from_list=old_list) | ||
|
|
||
| click.echo(ctx.formatter.detailed(todo)) | ||
|
|
||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice addition!