- invoke = inv: Comando principal que solo funciona donde hay un fichero tasks.py.
- invoke --help / -h: Listar opciones del comando invoke.
- invoke --list / -l: Lista de tareas disponibles en el fichero tasks.py.
Script tasks.py:
from invoke import task
@task
def build(c):
print("Building!")
@task
def clean(c, all=False):
if all:
print("Cleaning all!")
else:
print("Cleaning!")
@task(help = {"all":"Si se quiere limpiar todo.",
"only_one":"Si se quiere limpiar solo uno."})
def clean2(c, all=False, only_one = False):
if all:
print("Cleaning all!")
elif only_one:
print("Cleaning only-one.")
else:
print("Cleaning!")
Comandos para realizar estas tareas:
- invoke build: Devuelve
Building!
. - invoke clean: Devuelve
Cleaning!
. - invoke clean --all / -a: Devuelve
Cleaning all!
. - invoke clean2 --help / -h: Develve...
Options:
-a, --all Si se quiere limpiar todo.
-o, --only-one Si se quiere limpiar solo uno.
Script taskds.py:
from invoke import task
@task
def hello(c, who = ""):
if who == "":
msg = "hello world!!"
else:
msg = f"hello {who}!!"
c.run(f"echo '{msg}'")
Comandos para usar esta tarea:
- invoke hello: Devuelve
Hello world!!
. - invoke hello --who / -w: Devuelve
Hello world!!
. - invoke hello --who "Juan" / -w "Juan": Devuelve
Hello Juan!!
.
Script tasks.py:
from invoke import task
@task
def build(c):
print("Building!")
@task(build) # <--------------------------- Opcion 1 pre
def clean(c, all=False):
if all:
print("Cleaning all!")
else:
print("Cleaning!")
@task(pre=[build], post=[clean2]) # <----- Opcion 2 pre/post
def hello(c, who = ""):
if who == "":
msg = "hello world!!"
else:
msg = f"hello {who}!!"
c.run(f"echo '{msg}'")
Comandos para usar esta tarea:
- invoke clean: Devuelve...
Building!
Cleaning!
- invoke hello: Devuelve...
Building!
hello world!!
Cleaning!
Script others.py:
from invoke import task
@task
def other(c):
print("I am other task")
Script tasks.py:
from invoke import task, Collection
import others
@task
def build(c):
print("Building!")
namespace = Collection(others, build)
Comandos para usar esta tarea:
- invoke --list: Devuelve...
Available tasks:
build
others.other
- invoke others.other: Devuelve
I am other task
.