Add addp command for adding tasks with priority#471
Add addp command for adding tasks with priority#471rosconap wants to merge 2 commits intotodotxt:masterfrom
Conversation
- Implement addp PRIORITY "TASK" syntax to add tasks with specified priority (A-Z) - Priority is automatically converted to uppercase and formatted as (PRIORITY) - Add comprehensive error handling for invalid priorities (numbers, special chars, multiple chars) - Integrate with existing features like TODOTXT_DATE_ON_ADD and configuration options - Update help documentation in shorthelp() and actionsHelp() - Add complete documentation to USAGE.md with examples and usage patterns - Add comprehensive test suite (t1050-addp.sh) with 23 test cases covering: - Basic functionality and priority validation - Case conversion (lowercase to uppercase) - Integration with projects and contexts - Error handling for all invalid input scenarios - Configuration integration (date on add, priority on add overrides) - Edge cases with special characters and quotes Example usage: todo.sh addp A "High priority task" # Creates: (A) High priority task todo.sh addp c "Medium priority task" # Creates: (C) Medium priority task
inkarkat
left a comment
There was a problem hiding this comment.
This is a common add-on (here's mine), might as well be included in the core.
…plementation - Rename command from 'addp' to 'addpri|ap' to match existing patterns (add|a, pri|p) - Replace grep-based priority validation with modern Bash syntax - Update shorthelp() and actionsHelp() functions to show both command forms - Update USAGE.md documentation to reflect new command name - Replace dynamic date with hardcoded 2009-02-13 in tests per framework requirements - Rename test file from t1050-addp.sh to t1050-addpri.sh for consistency - Update all test references from addp to addpri throughout test suite
inkarkat
left a comment
There was a problem hiding this comment.
Looks good! I'd only use the example task text from add, not from addto. The TEXT TO ADD isn't very specific (as it's not necessarily a new task when adding to done.txt).
| add|a "THING I NEED TO DO +project @context" | ||
| addm "THINGS I NEED TO DO | ||
| MORE THINGS I NEED TO DO" | ||
| addpri|ap PRIORITY "TEXT TO ADD" |
There was a problem hiding this comment.
| addpri|ap PRIORITY "TEXT TO ADD" | |
| addpri|ap PRIORITY "THING I NEED TO DO +project @context" |
| addpri PRIORITY "TEXT TO ADD" | ||
| ap PRIORITY "TEXT TO ADD" | ||
| Adds TEXT TO ADD to your todo.txt file on its own line with |
There was a problem hiding this comment.
| addpri PRIORITY "TEXT TO ADD" | |
| ap PRIORITY "TEXT TO ADD" | |
| Adds TEXT TO ADD to your todo.txt file on its own line with | |
| addpri PRIORITY "THING I NEED TO DO +project @context" | |
| ap PRIORITY "THING I NEED TO DO +project @context" | |
| Adds THING I NEED TO DO to your todo.txt file on its own line with |
There was a problem hiding this comment.
Pull Request Overview
This PR adds a new addpri command that allows users to add tasks with a specified priority directly, streamlining the process of creating high-priority tasks.
Key changes:
- Implements
addpri PRIORITY "TASK"syntax with automatic priority validation and case conversion - Integrates with existing configuration options like TODOTXT_DATE_ON_ADD
- Provides comprehensive error handling for invalid priority inputs
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| todo.sh | Adds the core addpri command implementation with priority validation and integration |
| tests/t1050-addpri.sh | Comprehensive test suite covering functionality, edge cases, and error scenarios |
| USAGE.md | Documentation for the new addpri command with usage examples |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| addpri PRIORITY "TEXT TO ADD" | ||
| ap PRIORITY "TEXT TO ADD" |
There was a problem hiding this comment.
The help text shows both 'addpri' and 'ap' as separate commands, but they should be documented as aliases of each other. Consider formatting as 'addpri|ap PRIORITY "TEXT TO ADD"' to match the pattern used elsewhere in the help.
| addpri PRIORITY "TEXT TO ADD" | |
| ap PRIORITY "TEXT TO ADD" | |
| addpri|ap PRIORITY "TEXT TO ADD" |
| [ -z "$3" ] && die "$errmsg" | ||
|
|
||
| # Validate priority is a single letter A-Z | ||
| if [[ "$priority" != @([A-Za-z]) ]]; then |
There was a problem hiding this comment.
The extended glob pattern @([A-Za-z]) requires 'shopt -s extglob' to be set. Consider using a more portable approach like '[[ ${#priority} -eq 1 && "$priority" =~ ^[A-Za-z]$ ]]' or ensure extglob is enabled in the script.
| if [[ "$priority" != @([A-Za-z]) ]]; then | |
| if [[ ! "$priority" =~ ^[A-Za-z]$ ]]; then |
Adding
addpto insert new tasks with priority.Example usage:
Before submitting a pull request, please make sure the following is done:
master.fixes #XXreference to the issue that this pull request fixes.