Last active
December 16, 2024 01:47
-
-
Save GaryLee/030aa2fd36db22e813784bc14c2ae604 to your computer and use it in GitHub Desktop.
An example showing how to use invoke as standalone program.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!python | |
# coding: utf-8 | |
import sys | |
from invoke import task, Program, Collection | |
@task | |
def task1(c): | |
# c.run will invoke a shell context to run the commands. | |
c.run("echo Put your first task command here.") | |
@task | |
def task2(c, arg1, arg2): | |
# The arguments can be set by command line options. | |
# invoke task1 --arg1="xxx" --arg2="yyy" | |
c.run(f"echo Put your second task command here. {arg1=}, {arg2=}") | |
if __name__ == '__main__': | |
# The namespace Collection allows you to invoke tasks like this: | |
# > python tasks.py task1 | |
# > python tasks.py task2 | |
# Of course, you can invoke tasks via invoke program as usual. | |
# > invoke task1 | |
# > invoke task2 | |
local_task_collection = Collection.from_module(sys.modules[__name__]) | |
Program(namespace=local_task_collection, version="1.0").run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment