Last active
December 24, 2021 12:19
-
-
Save ivangeorgiev/574eb3198b011a107ee018326d0ff6de to your computer and use it in GitHub Desktop.
Python tasks with invoke
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
import invoke | |
import io | |
@invoke.task | |
def ls(ctx): | |
result = ctx.run("dir", hide="out") | |
lines = [line.strip() for line in io.StringIO(result.stdout) if not line.startswith(" ")] | |
filenames = [fn for *_, fn in [line.rsplit(" ", 1) for line in lines if line != ""]] | |
print("\n".join(filenames)) |
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
import invoke | |
@invoke.task | |
def greet(ctx, name=None): | |
"""Greet user.""" | |
if name is not None: | |
print(f"Hello {name}!") | |
else: | |
print("Hi there!") |
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
import invoke | |
@invoke.task(help={ | |
"name": "Name of the person to greet.", | |
}) | |
def greet(ctx, name=None): | |
"""Greet user.""" | |
if name is not None: | |
print(f"Hello {name}!") | |
else: | |
print("Hi there!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment