Skip to content

Add addp command for adding tasks with priority#471

Open
rosconap wants to merge 2 commits intotodotxt:masterfrom
rosconap:feature/addp-command
Open

Add addp command for adding tasks with priority#471
rosconap wants to merge 2 commits intotodotxt:masterfrom
rosconap:feature/addp-command

Conversation

@rosconap
Copy link

@rosconap rosconap commented Sep 29, 2025

Adding addp to insert new tasks with priority.

  • 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

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.
  • Lint 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.

- 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
Copy link
Member

@inkarkat inkarkat left a comment

Choose a reason for hiding this comment

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

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
@rosconap
Copy link
Author

Updated with ecae92f to address @inkarkat 's feedback. Shamefully i did not check out the add-on feature yet.

Copy link
Member

@inkarkat inkarkat left a comment

Choose a reason for hiding this comment

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

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"
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
addpri|ap PRIORITY "TEXT TO ADD"
addpri|ap PRIORITY "THING I NEED TO DO +project @context"

Comment on lines +181 to +183
addpri PRIORITY "TEXT TO ADD"
ap PRIORITY "TEXT TO ADD"
Adds TEXT TO ADD to your todo.txt file on its own line with
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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

@karbassi karbassi requested a review from Copilot October 2, 2025 01:29
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.

Comment on lines +181 to +182
addpri PRIORITY "TEXT TO ADD"
ap PRIORITY "TEXT TO ADD"
Copy link

Copilot AI Oct 2, 2025

Choose a reason for hiding this comment

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

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.

Suggested change
addpri PRIORITY "TEXT TO ADD"
ap PRIORITY "TEXT TO ADD"
addpri|ap PRIORITY "TEXT TO ADD"

Copilot uses AI. Check for mistakes.

Choose a reason for hiding this comment

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

Implemented.

[ -z "$3" ] && die "$errmsg"

# Validate priority is a single letter A-Z
if [[ "$priority" != @([A-Za-z]) ]]; then
Copy link

Copilot AI Oct 2, 2025

Choose a reason for hiding this comment

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

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.

Suggested change
if [[ "$priority" != @([A-Za-z]) ]]; then
if [[ ! "$priority" =~ ^[A-Za-z]$ ]]; then

Copilot uses AI. Check for mistakes.

Choose a reason for hiding this comment

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

Implemented.

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.

4 participants