-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Cmds class for multiple functions / commands (#24)
- Loading branch information
Showing
23 changed files
with
423 additions
and
70 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,5 +24,8 @@ venv/ | |
.coverage | ||
coverage.lcov | ||
|
||
# Mypy | ||
.mypy_cache/ | ||
|
||
# hatchling autogenerates version | ||
/startle/_version.py |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
from startle import start | ||
|
||
|
||
def add(a: int, b: int) -> None: | ||
""" | ||
Add two numbers. | ||
Args: | ||
a: The first number. | ||
b: The second number. | ||
""" | ||
print(f"{a} + {b} = {a + b}") | ||
|
||
|
||
def sub(a: int, b: int) -> None: | ||
""" | ||
Subtract two numbers. | ||
Args: | ||
a: The first number. | ||
b: The second number | ||
""" | ||
print(f"{a} - {b} = {a - b}") | ||
|
||
|
||
def mul(a: int, b: int) -> None: | ||
""" | ||
Multiply two numbers. | ||
Args: | ||
a: The first number. | ||
b: The second number. | ||
""" | ||
print(f"{a} * {b} = {a * b}") | ||
|
||
|
||
def div(a: int, b: int) -> None: | ||
""" | ||
Divide two numbers. | ||
Args: | ||
a: The dividend. | ||
b: The divisor. | ||
""" | ||
print(f"{a} / {b} = {a / b}") | ||
|
||
|
||
if __name__ == "__main__": | ||
start([add, sub, mul, div]) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
""" | ||
Example invocations (for fish shell): | ||
❯ python examples/cat.py examples/wc.py examples/cat.py --delim=\n===\n\n | ||
❯ python examples/cat.py --delim=\n===\n\n examples/cat.py examples/wc.py | ||
""" | ||
|
||
from pathlib import Path | ||
|
||
from startle import start | ||
|
||
|
||
def cat(files: list[Path], /, *, delim: str = "") -> None: | ||
""" | ||
Concatenate files with an optional delimiter. | ||
Args: | ||
files: The files to concatenate. | ||
delim: The delimiter to use. | ||
""" | ||
|
||
for i, file in enumerate(files): | ||
if i: | ||
print(delim, end="") | ||
print(file.read_text(), end="") | ||
|
||
|
||
start(cat) |
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.