Skip to content
This repository was archived by the owner on Jan 23, 2026. It is now read-only.

Commit e0a3c55

Browse files
authored
Merge pull request #366 from jumpstarter-dev/less-options
Deduplicate click options
2 parents 36015dd + 86ddbbc commit e0a3c55

7 files changed

Lines changed: 23 additions & 37 deletions

File tree

packages/jumpstarter-cli-client/jumpstarter_cli_client/client_login.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import asyncclick as click
22
from jumpstarter_cli_common.exceptions import async_handle_exceptions
3-
from jumpstarter_cli_common.oidc import Config, decode_jwt_issuer, opt_client_id, opt_connector_id
3+
from jumpstarter_cli_common.oidc import Config, decode_jwt_issuer, opt_oidc
44

55
from jumpstarter.common.exceptions import FileNotFoundError
66
from jumpstarter.config import ClientConfigV1Alpha1, ClientConfigV1Alpha1Drivers, ObjectMeta, UserConfigV1Alpha1
@@ -27,15 +27,6 @@
2727
help="Enter the Jumpstarter client name.",
2828
default=None,
2929
)
30-
@click.option("--username", type=str, help="Enter the OIDC username.", default=None)
31-
@click.option("--password", type=str, help="Enter the OIDC password.", default=None)
32-
@click.option("--token", type=str, help="Enter the OIDC token.", default=None)
33-
@click.option(
34-
"--issuer",
35-
type=str,
36-
help="Enter the OIDC issuer.",
37-
default=None,
38-
)
3930
@click.option(
4031
"--allow",
4132
type=str,
@@ -45,8 +36,7 @@
4536
@click.option(
4637
"--unsafe", is_flag=True, help="Should all driver client packages be allowed to load (UNSAFE!).", default=None
4738
)
48-
@opt_client_id
49-
@opt_connector_id
39+
@opt_oidc
5040
@async_handle_exceptions
5141
async def client_login( # noqa: C901
5242
alias: str,

packages/jumpstarter-cli-client/jumpstarter_cli_client/client_shell.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
import asyncclick as click
55
from jumpstarter_cli_common.exceptions import handle_exceptions
66

7-
from .common import opt_config, opt_duration_partial, opt_selector_simple
7+
from .common import opt_config, opt_duration_partial, opt_selector
88
from jumpstarter.common.utils import launch_shell
99

1010

1111
@click.command("shell", short_help="Spawns a shell connecting to a leased remote exporter")
1212
@click.option("-n", "--lease", "lease_name", type=str)
1313
@opt_config
14-
@opt_selector_simple
14+
@opt_selector
1515
@opt_duration_partial(default=timedelta(minutes=30), show_default="00:30:00")
1616
@handle_exceptions
1717
def client_shell(config, selector: str, duration: timedelta, lease_name):

packages/jumpstarter-cli-client/jumpstarter_cli_client/common.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,6 @@
1616
" Matching objects must satisfy all of the specified label constraints.",
1717
)
1818

19-
opt_selector_simple = click.option(
20-
"-l",
21-
"--selector",
22-
help="Selector (label query) to filter on, only supports '=', (e.g. -l key1=value1,key2=value2)."
23-
" Matching objects must satisfy all of the specified label constraints.",
24-
required=True,
25-
)
26-
2719

2820
class ClientParamType(click.ParamType):
2921
name = "client"

packages/jumpstarter-cli-client/jumpstarter_cli_client/create.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
)
1010
from jumpstarter_cli_common.exceptions import handle_exceptions
1111

12-
from .common import opt_config, opt_duration_partial, opt_selector_simple
12+
from .common import opt_config, opt_duration_partial, opt_selector
1313

1414

1515
@click.group()
@@ -21,7 +21,7 @@ def create():
2121

2222
@create.command(name="lease")
2323
@opt_config
24-
@opt_selector_simple
24+
@opt_selector
2525
@opt_duration_partial(required=True)
2626
@opt_output_all
2727
@handle_exceptions

packages/jumpstarter-cli-client/jumpstarter_cli_client/update.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from jumpstarter_cli_common import OutputMode, OutputType, make_table, opt_output_all
55
from jumpstarter_cli_common.exceptions import handle_exceptions
66

7-
from .common import DURATION, opt_config
7+
from .common import opt_config, opt_duration_partial
88

99

1010
@click.group()
@@ -17,7 +17,7 @@ def update():
1717
@update.command(name="lease")
1818
@opt_config
1919
@click.argument("name")
20-
@click.option("--duration", "duration", type=DURATION, required=True)
20+
@opt_duration_partial(required=True)
2121
@opt_output_all
2222
@handle_exceptions
2323
async def update_lease(config, name: str, duration: timedelta, output: OutputType):

packages/jumpstarter-cli-common/jumpstarter_cli_common/oidc.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import json
22
import os
33
from dataclasses import dataclass
4+
from functools import wraps
45
from typing import ClassVar
56

67
import aiohttp
@@ -21,10 +22,18 @@
2122
truststore.inject_into_ssl()
2223

2324

24-
opt_client_id = click.option("--client-id", "client_id", type=str, default="jumpstarter-cli", help="OIDC client id")
25-
opt_connector_id = click.option(
26-
"--connector-id", "connector_id", type=str, help="OIDC token exchange connector id (Dex specific)"
27-
)
25+
def opt_oidc(f):
26+
@click.option("--issuer", help="OIDC issuer")
27+
@click.option("--client-id", "client_id", help="OIDC client id", default="jumpstarter-cli")
28+
@click.option("--token", help="OIDC access token")
29+
@click.option("--username", help="OIDC username")
30+
@click.option("--password", help="OIDC password")
31+
@click.option("--connector-id", "connector_id", help="OIDC token exchange connector id (Dex specific)")
32+
@wraps(f)
33+
def wrapper(*args, **kwds):
34+
return f(*args, **kwds)
35+
36+
return wrapper
2837

2938

3039
@dataclass(kw_only=True)

packages/jumpstarter-cli-exporter/jumpstarter_cli_exporter/exporter_login.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import asyncclick as click
2-
from jumpstarter_cli_common.oidc import Config, decode_jwt_issuer, opt_client_id, opt_connector_id
2+
from jumpstarter_cli_common.oidc import Config, decode_jwt_issuer, opt_oidc
33

44
from jumpstarter.config.exporter import ExporterConfigV1Alpha1, ObjectMeta
55

@@ -9,12 +9,7 @@
99
@click.option("-e", "--endpoint", type=str, help="Enter the Jumpstarter service endpoint.", default=None)
1010
@click.option("--namespace", type=str, help="Enter the Jumpstarter exporter namespace.", default=None)
1111
@click.option("--name", type=str, help="Enter the Jumpstarter exporter name.", default=None)
12-
@click.option("--username", type=str, help="Enter the OIDC username.", default=None)
13-
@click.option("--password", type=str, help="Enter the OIDC password.", default=None)
14-
@click.option("--token", type=str, help="Enter the OIDC token.", default=None)
15-
@click.option("--issuer", type=str, help="Enter the OIDC issuer.", default=None)
16-
@opt_client_id
17-
@opt_connector_id
12+
@opt_oidc
1813
async def exporter_login(
1914
alias: str,
2015
endpoint: str,

0 commit comments

Comments
 (0)