Skip to content

Conversation

leaanthony
Copy link
Contributor

Overview

This PR introduces a new overrides keyword that allows Taskfiles to override tasks from other Taskfiles, providing a more flexible way to customize and extend task definitions. I have taken what was done in the includes directive and mapped it to overrides.

Key Features

  • Task replacement: Unlike includes which errors on duplicate task names, overrides replaces existing tasks with the overridden version
  • Automatic flattening: Overridden tasks are automatically available in the local namespace without prefixes
  • Nested overrides: Support for multi-level override chains with proper precedence
  • Full feature parity: Supports all include options (optional, internal, vars, dir, excludes, aliases)

Implementation Details

New Files

  • taskfile/ast/override.go - Core override functionality and AST node definition
  • testdata/overrides/ - Comprehensive test cases for override functionality
  • testdata/overrides_cycle/ - Cycle detection tests
  • testdata/overrides_flatten/ - Flattening behavior tests
  • testdata/overrides_interpolation/ - Variable interpolation tests
  • testdata/overrides_nested/ - Nested override tests
  • testdata/overrides_optional/ - Optional override tests
  • testdata/overrides_with_includes/ - Combined includes/overrides tests
  • testdata/overrides_with_vars/ - Variable override tests

Modified Files

  • taskfile/ast/taskfile.go - Added Overrides field to Taskfile struct
  • taskfile/reader.go - Override processing logic with cycle detection
  • task_test.go - Comprehensive test coverage for all override scenarios
  • website/docs/usage.mdx - Documentation for the new feature
  • Various schema and parsing files for YAML/JSON support

Usage Example

  version: '3'

  overrides:
    lib:
      taskfile: ./overrides.yml

  tasks:
    greet:
      cmds:
        - echo "Original"

If ./overrides.yml contains a greet task, it will replace the original version.

Testing

  • Added extensive test coverage including:
    • Basic override functionality
    • Cycle detection and prevention
    • Nested overrides with proper precedence
    • Variable interpolation in overrides
    • Integration with existing includes
    • Optional and internal override modes
    • Task exclusion from overrides

Documentation

  • Added comprehensive documentation in website/docs/usage.mdx covering:
    • Basic usage and syntax
    • Key differences from includes
    • All configuration options
    • Integration patterns with existing features
    • Multiple examples with tabbed code blocks

Backwards Compatibility

  • Fully backwards compatible - existing Taskfiles continue to work unchanged
  • The overrides keyword is optional and only processed when present
  • Works alongside existing includes functionality

@trulede
Copy link
Contributor

trulede commented Aug 9, 2025

Could you use the existing ´imports´ schema with flatten, and then adjust the behaviour which currently results in the error "If multiple tasks have the same name, an error will be thrown:"?

version: '3'
includes:
  lib:
    taskfile: ./Included.yml
    override: true  # flatten is implicit with this option, perhaps.

@leaanthony
Copy link
Contributor Author

Could you use the existing ´imports´ schema with flatten, and then adjust the behaviour which currently results in the error "If multiple tasks have the same name, an error will be thrown:"?

version: '3'
includes:
  lib:
    taskfile: ./Included.yml
    override: true  # flatten is implicit with this option, perhaps.

That was my original idea but @andreynering suggested creating a separate key. I may have misinterpreted the request, which is fine, we can adjust.

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.

2 participants