Skip to content
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

Allow parameters for todo.sh default action #407

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

chrysle
Copy link
Contributor

@chrysle chrysle commented Mar 6, 2023

Before submitting a pull request, please make sure the following is done:

  • Fork the repository and create your branch from master.
  • If you've added code that should be tested, add tests!
  • Ensure the test suite passes.
  • Format your code with ShellCheck.
  • Include a human-readable description of what the pull request is trying to accomplish.
  • Steps for the reviewer(s) on how they can manually QA the changes.
  • Have a fixes #XX reference to the issue that this pull request fixes.

This finishes leftover work from #159
That PR can be closed then.

I added a test, a docstring and also a note for TODOTXT_DEFAULT_ACTION to the config file.

@inkarkat
Copy link
Member

inkarkat commented Mar 6, 2023

Unfortunately, you're written the test to match the implementation, not to actually verify the specified behavior; and that actually was broken (good that we insisted on having tests). I've corrected both in my commit. It still doesn't handle default parameters that have spaces or other special characters; I'll add that later.

@chrysle
Copy link
Contributor Author

chrysle commented Mar 7, 2023

Thanks for your help! What special parameters for example do you mean that should be tested?

@chrysle
Copy link
Contributor Author

chrysle commented Mar 23, 2023

@inkarkat I would like to relieve you of implementing the tests if ou give me some hints.

… by the action

The foo2 action needs to print its parameters (minus the first which is the action name, instead of hard-coding "foo" if no parameters are passed (which also is broken because the $# is already expanded in the here-doc)), and the test needs to include "foo" (instead of "bar") to match the (reused) expected output.
@inkarkat inkarkat force-pushed the allow-params-default-action branch from 4622dc5 to 780c114 Compare April 3, 2023 21:04
Copy link
Contributor Author

@chrysle chrysle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have left some comments.

tests/t0002-actions.sh Outdated Show resolved Hide resolved
tests/t0002-actions.sh Outdated Show resolved Hide resolved
todo.sh Show resolved Hide resolved
…tion

Spaces, quotes, $, and other special shell characters need to be escaped inside the TODOTXT_DEFAULT_ACTION, and consequently eval() used to parse that back into individual arguments.
Only $TODO_ACTIONS_DIR/$action, not even the $TODO_ACTIONS_DIR/$action/$action variant.
A totally different approach is needed: Instead of parsing off the first argument and treating that as the custom action, do a recursive invocation with the default action parsed as a command-line. A new isDefaultAction flag is needed so that we only do this when the default action actually applies (otherwise, strange invocations like todo.sh "add +project here" would also be possible). The condition for non-empty $TODOTXT_DEFAULT_ACTION avoids an endless loop.
@inkarkat inkarkat force-pushed the allow-params-default-action branch from 780c114 to e71eb46 Compare April 4, 2023 15:18
@inkarkat
Copy link
Member

inkarkat commented Apr 4, 2023

Thanks for the review @chrysle; the original implementation was woefully incomplete and wrong, but only writing the tests showed what looked quite alright to a casual review. From my point of view this is now done, and we just have to wait for the merge of the huge backlog of open issues...

@chrysle
Copy link
Contributor Author

chrysle commented Apr 4, 2023

Did you notice the test for macOS 10.15 succeeded? I wonder why it was always cancelled before.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants