You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add an example for a CLI app also used as a Hera script (#1536)
**Pull Request Checklist**
- [x] Related to #1530
- [x] Tests added
- [x] Documentation/examples added
- [x] [Good commit messages](https://cbea.ms/git-commit/) and/or PR
title
**Description of PR**
Currently, a user may want to reuse a CLI app with Hera. `click` is a
popular choice but garbles the underlying function, rendering it
unusable with the `script` decorator (and not worth first-party support
at this time). Cappa, used for the `hera` CLI itself, does not interfere
with the function, so it is usable with the script decorator.
This PR adds a use-case/integration example for reusing a CLI app with
Hera. Also pointing out in a warning box that `click` will not
ordinarily work with the `script` decorator (requiring the `Script`
class).
cc @DanCardin sharing the cappa love 🫶
Signed-off-by: Elliot Gunton <[email protected]>
Co-authored-by: Sambhav Kothari <[email protected]>
This example shows how a CLI application built with [Cappa](https://github.com/DanCardin/cappa) can also be used as a `script` function.
6
+
7
+
!!! Warning
8
+
Using the `script` decorator is not possible with other CLI libraries like [`click`](https://click.palletsprojects.com/en/stable/), and will require use of the `Script` class and setting `source=function_name`.
9
+
[See this issue discussion](https://github.com/argoproj-labs/hera/issues/1530#issuecomment-3616082722) for more details.
10
+
11
+
12
+
=== "Hera"
13
+
14
+
```python linenums="1"
15
+
import cappa
16
+
17
+
from hera.workflows import Workflow, script
18
+
19
+
20
+
@script()
21
+
def hello(count: int, name: str):
22
+
"""Simple program that greets NAME for a total of COUNT times."""
"""This example shows how a CLI application built with [Cappa](https://github.com/DanCardin/cappa) can also be used as a `script` function.
2
+
3
+
!!! Warning
4
+
Using the `script` decorator is not possible with other CLI libraries like [`click`](https://click.palletsprojects.com/en/stable/), and will require use of the `Script` class and setting `source=function_name`.
5
+
[See this issue discussion](https://github.com/argoproj-labs/hera/issues/1530#issuecomment-3616082722) for more details.
6
+
"""
7
+
8
+
importcappa
9
+
10
+
fromhera.workflowsimportWorkflow, script
11
+
12
+
13
+
@script()
14
+
defhello(count: int, name: str):
15
+
"""Simple program that greets NAME for a total of COUNT times."""
0 commit comments