Skip to content

Add flag to include a Taskfile as un-namespaced #1271

Closed as not planned
Closed as not planned

Description

@Gowiem

General Idea

I would like the ability to include a Taskfile without causing the included tasks to get namespaced.

Situation

I have the following Taskfiles:

# taskfiles/a/Taskfile.yaml
tasks:
  # ... 
# taskfiles/b/Taskfile.yaml
tasks:
  # ... 
# taskfiles/Taskfile.yaml
includes:
  a: ./a
  b: ./b
# ... 
# Taskfile.yaml in ANOTHER PROJECT
version: "3"

includes:
  remote:
    taskfile: .remote/taskfiles/Taskfile.yaml
    optional: true # Optional only until we have init'd 
    aliases: [r]

# Load our project specific variables from .env
dotenv: [.env]

vars:
  REMOTE_BRANCH: master
  REMOTE_LOCAL_PATH: ""

tasks:
  default:
    desc: Initializes the Taskfile setup for this project by downloading the remote Taskfile automation repo.
    silent: true
    aliases: [init]
    cmds:
      - |
        if [ -d .remote ]; then
          rm -rf .remote/
        fi

        mkdir -p .remote

        if [[ -z "${REMOTE_LOCAL_PATH}" ]]; then
          echo "Copying remote from local path..."
          rsync -rq --exclude=.git --exclude=**/.terraform {{.REMOTE_LOCAL_PATH}} .remote
        else
          echo "Downloading remote from remote repo..."
          git clone -b {{.REMOTE_BRANCH}} <remote repo URL> .remote
        fi

When initialized and the remote taskfiles are included, this results in is a list of tasks like this:

CleanShot 2023-07-19 at 17 17 13

What I don't like about that is the remote namespace is unnecessary and complicates running tasks.

Proposed solution

Add a unnamespace field to the includes object, so something like this:

includes:
  remote:
    taskfile: .remote/taskfiles/Taskfile.yaml
    optional: true # Optional only until we have init'd 
    unnamespace: true

unnamespace default to false, but if set to true, will remove the includes namespace from all tasks that are included from that file. For example, my above screenshot (calling task -l would turn into our tasks being like this:

* snaplet:capture
* snaplet:download
* snaplet:list
* snaplet:restore
* snaplet:upload
* toolbox:all
* toolbox:build
* toolbox:install
* toolbox:pull
* toolbox:run

This would allow us to simplify and opt out of namespaces where convenient.

Activity

  1. pd93 commented on Jul 19, 2023

    @pd93
    Member

    Closing as a duplicate of #273. Please feel free to upvote/comment over there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions