-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ability to define functions that aren't exposed as tasks #3
Comments
not sure if this is the best way, but you check if the helper task if any arg was passed (i.e.: |
I am doing this, maybe it helps #!/bin/bash
function sayhellomars() {
echo "hello mars"
}
function public:hellomars() {
sayhellomars
}
function public:helloworld() {
echo "hello world"
}
# DEFAULT public: list all possible commands
function public:help {
echo "$0 <task> <args>"
echo "Tasks:"
compgen -A function | sed -En 's/public:(.*)/\1/p' | cat -n
}
TIMEFORMAT="Task completed in %3lR"
time "public:${@:-help}" # make help default ./taskfile help ~/bin(master*) » ./taskfile help
./taskfile <task> <args>
Tasks:
1 hellomars
2 helloworld
3 help ./taskfile sayhellomars ~/bin(master*) » ./taskfile sayhellomars
./taskfile: line 27: public:sayhellomars: command not found |
@brenwell Ah I see, the |
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:
It would be really nice if I could do this instead:
And then the help menu would only show the
flask
andflake8
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?
The text was updated successfully, but these errors were encountered: