Skip to content

Instantly share code, notes, and snippets.

@nazfox
Last active February 20, 2022 09:52
Show Gist options
  • Save nazfox/193af50fc7389097ac58681d73be9a4b to your computer and use it in GitHub Desktop.
Save nazfox/193af50fc7389097ac58681d73be9a4b to your computer and use it in GitHub Desktop.
Using the invoke task runner from a shell script. The command name displayed in the help message of invoke becomes this shellscript filename.
#!/usr/bin/bash
install_stamp=".install.stamp"
ver="0.1.0"
function find_command() {
type $1 > /dev/null 2>&1
}
function pipenv_error() {
echo "Can't find pipenv. See https://pipenv.pypa.io/en/latest/install/"
exit 1
}
function is_depends_installed() {
if [ -e $install_stamp ]; then
return 0
else
return 1
fi
}
function install_depends() {
read -n1 -p "Can I install the dependencies using pipenv? [Y/n]: " yn
echo ""
if [[ "$yn" = [nN] ]]; then
echo "We need to install the dependencies."
exit 1
else
pipenv install
echo ""
touch $install_stamp
fi
}
find_command pipenv || pipenv_error
is_depends_installed || install_depends
pipenv run python - $@ <<EOF
import sys
import tasks
from invoke import Collection, Program
sys.argv[0] = '$0'
program = Program(namespace=Collection.from_module(tasks), version='$ver')
program.run()
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment