Skip to content

Ability to define functions that aren't exposed as tasks #3

@nickjj

Description

@nickjj

Hey, great idea btw. Really enjoying this pattern.

But I ran into a situation where I would very much like to add a function into my Taskfile but not have it be runnable directly, or perhaps as a compromise not be listed in the help menu.

This comes in handy when you want to define a "helper" function that multiple tasks can call.

For example, currently I have some tasks that look like this:

function flask {
  ## Run any Flask commands
  docker-compose exec web flask "${@}"
}

function flake8 {
  ## Lint Python code with flake8
  docker-compose exec web flake8 "${@}"
}

It would be really nice if I could do this instead:

function _web {
  docker-compose exec web "${@}"
}

function flask {
  ## Run any Flask commands
  _web flask "${@}"
}

function flake8 {
  ## Lint Python code with flake8
  _web flake8 "${@}"
}

And then the help menu would only show the flask and flake8 commands and running _web directly would throw a command not found.

I figured we could mark these helper functions with an underscore to distinguish what should be private or not.

Method I've tried so far that partially works

You can do compgen -A function | grep -v "^_" | cat -n which hides them from the task list but technically you can still run the helper functions directly.

Any thoughts on how to do this in a better way?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions