Skip to content

Commit ebcc4ef

Browse files
authored
fix(client): remove import from cli in beiboot api (#61)
Signed-off-by: Michael Schilonka <[email protected]>
1 parent 8f9d454 commit ebcc4ef

File tree

3 files changed

+37
-24
lines changed

3 files changed

+37
-24
lines changed

client/beiboot/types.py

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22
import logging
33
from datetime import datetime
44
from time import sleep
5-
from cli.utils import TimeDelta
65

76
import kubernetes as k8s
87

98
from dataclasses import dataclass, field, fields
109
from enum import Enum
11-
from typing import Dict, List, Optional, Any, Union
10+
from typing import Dict, Optional, Any, Union
1211

1312
from beiboot.configuration import (
1413
default_configuration,
@@ -350,15 +349,13 @@ class InstallOptions:
350349
max_session_timeout: str = field(
351350
default_factory=lambda: "null",
352351
metadata=dict(
353-
help="The default maximum session timeout for a Beiboot cluster before it will be deleted (default: null)",
354-
type=TimeDelta(name="max_session_timeout"),
352+
help="The default maximum session timeout for a Beiboot cluster before it will be deleted (default: null)"
355353
),
356354
)
357355
max_lifetime: str = field(
358356
default_factory=lambda: "null",
359357
metadata=dict(
360-
help="The default maximum lifetime for a Beiboot cluster before it will be deleted (default: null)",
361-
type=TimeDelta(name="max_lifetime"),
358+
help="The default maximum lifetime for a Beiboot cluster before it will be deleted (default: null)"
362359
),
363360
)
364361
namespace_prefix: str = field(
@@ -391,19 +388,3 @@ class InstallOptions:
391388
help="The default memory request for each Beiboot node pod (default: 1Gi)",
392389
),
393390
)
394-
395-
@classmethod
396-
def to_cli_options(cls) -> List[Dict[str, Union[bool, str, Any, None]]]:
397-
result = []
398-
for _field in fields(cls):
399-
result.append(
400-
dict(
401-
name=_field.name,
402-
long=_field.name.replace("_", "-"),
403-
short=_field.metadata.get("short"),
404-
required=False,
405-
help=_field.metadata.get("help"),
406-
type=_field.metadata.get("type") or "string",
407-
)
408-
)
409-
return result

client/cli/install.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@
1616
from beiboot.types import InstallOptions
1717

1818
from cli.console import error, info
19-
from cli.utils import multi_options, standard_error_handler
19+
from cli.utils import (
20+
installoptions_to_cli_options,
21+
multi_options,
22+
standard_error_handler,
23+
)
2024
from cli.__main__ import cli as _cli
2125

2226
PRESETS = {
@@ -43,7 +47,7 @@
4347
type=str,
4448
)
4549
@click.pass_context
46-
@multi_options(InstallOptions.to_cli_options())
50+
@multi_options(installoptions_to_cli_options())
4751
@standard_error_handler
4852
def install(ctx, component, preset, **kwargs):
4953
if preset:

client/cli/utils.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
from dataclasses import fields
12
from datetime import timedelta
3+
from typing import Any, Dict, List, Union
4+
from beiboot.types import InstallOptions
25
import click
36
from click import ClickException
47

@@ -221,3 +224,28 @@ def decorator(f):
221224
return f
222225

223226
return decorator
227+
228+
229+
def installoptions_to_cli_options() -> List[Dict[str, Union[bool, str, Any, None]]]:
230+
result = []
231+
for _field in fields(InstallOptions):
232+
if _field.name in ["max_session_timeout", "max_lifetime"]:
233+
_data = dict(
234+
name=_field.name,
235+
long=_field.name.replace("_", "-"),
236+
short=_field.metadata.get("short"),
237+
required=False,
238+
help=_field.metadata.get("help"),
239+
type=TimeDelta(name=_field.name),
240+
)
241+
else:
242+
_data = dict(
243+
name=_field.name,
244+
long=_field.name.replace("_", "-"),
245+
short=_field.metadata.get("short"),
246+
required=False,
247+
help=_field.metadata.get("help"),
248+
type=_field.metadata.get("type") or "string",
249+
)
250+
result.append(_data)
251+
return result

0 commit comments

Comments
 (0)