Skip to content

Commit 1e6b3e1

Browse files
feat: leverage reusable cli standard options
Signed-off-by: Jesús Fernández <7312236+fernandezcuesta@users.noreply.github.com>
1 parent fb9e852 commit 1e6b3e1

2 files changed

Lines changed: 5 additions & 39 deletions

File tree

function/main.py

Lines changed: 4 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,16 @@
11
"""The composition function's main CLI."""
22

33
import click
4-
from crossplane.function import logging, runtime
4+
from crossplane.function import cli as sdkcli
55

66
from function import fn
77

88

99
@click.command()
10-
@click.option(
11-
"--debug",
12-
"-d",
13-
is_flag=True,
14-
help="Emit debug logs.",
15-
)
16-
@click.option(
17-
"--address",
18-
default="0.0.0.0:9443",
19-
show_default=True,
20-
help="Address at which to listen for gRPC connections",
21-
)
22-
@click.option(
23-
"--tls-certs-dir",
24-
help="Serve using mTLS certificates.",
25-
envvar="TLS_SERVER_CERTS_DIR",
26-
)
27-
@click.option(
28-
"--insecure",
29-
is_flag=True,
30-
help="Run without mTLS credentials. "
31-
"If you supply this flag --tls-certs-dir will be ignored.",
32-
)
33-
def cli(debug: bool, address: str, tls_certs_dir: str, insecure: bool) -> None: # noqa:FBT001 # We only expect callers via the CLI.
10+
@sdkcli.standard_options
11+
def cli(**kwargs):
3412
"""A Crossplane composition function."""
35-
try:
36-
level = logging.Level.INFO
37-
if debug:
38-
level = logging.Level.DEBUG
39-
logging.configure(level=level)
40-
runtime.serve(
41-
fn.FunctionRunner(),
42-
address,
43-
creds=runtime.load_credentials(tls_certs_dir),
44-
insecure=insecure,
45-
)
46-
except Exception as e:
47-
click.echo(f"Cannot run function: {e}")
13+
sdkcli.run(fn.FunctionRunner(), **kwargs)
4814

4915

5016
if __name__ == "__main__":

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ classifiers = [
1717
]
1818

1919
dependencies = [
20-
"crossplane-function-sdk-python==0.14.0",
20+
"crossplane-function-sdk-python==0.15.0",
2121
"click==8.5.0",
2222
"grpcio>=1.73.1",
2323
]

0 commit comments

Comments
 (0)