Skip to content

fix(client): remove import from cli in beiboot api #61

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 3 additions & 22 deletions client/beiboot/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
import logging
from datetime import datetime
from time import sleep
from cli.utils import TimeDelta

import kubernetes as k8s

from dataclasses import dataclass, field, fields
from enum import Enum
from typing import Dict, List, Optional, Any, Union
from typing import Dict, Optional, Any, Union

from beiboot.configuration import (
default_configuration,
Expand Down Expand Up @@ -350,15 +349,13 @@ class InstallOptions:
max_session_timeout: str = field(
default_factory=lambda: "null",
metadata=dict(
help="The default maximum session timeout for a Beiboot cluster before it will be deleted (default: null)",
type=TimeDelta(name="max_session_timeout"),
help="The default maximum session timeout for a Beiboot cluster before it will be deleted (default: null)"
),
)
max_lifetime: str = field(
default_factory=lambda: "null",
metadata=dict(
help="The default maximum lifetime for a Beiboot cluster before it will be deleted (default: null)",
type=TimeDelta(name="max_lifetime"),
help="The default maximum lifetime for a Beiboot cluster before it will be deleted (default: null)"
),
)
namespace_prefix: str = field(
Expand Down Expand Up @@ -391,19 +388,3 @@ class InstallOptions:
help="The default memory request for each Beiboot node pod (default: 1Gi)",
),
)

@classmethod
def to_cli_options(cls) -> List[Dict[str, Union[bool, str, Any, None]]]:
result = []
for _field in fields(cls):
result.append(
dict(
name=_field.name,
long=_field.name.replace("_", "-"),
short=_field.metadata.get("short"),
required=False,
help=_field.metadata.get("help"),
type=_field.metadata.get("type") or "string",
)
)
return result
8 changes: 6 additions & 2 deletions client/cli/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@
from beiboot.types import InstallOptions

from cli.console import error, info
from cli.utils import multi_options, standard_error_handler
from cli.utils import (
installoptions_to_cli_options,
multi_options,
standard_error_handler,
)
from cli.__main__ import cli as _cli

PRESETS = {
Expand All @@ -43,7 +47,7 @@
type=str,
)
@click.pass_context
@multi_options(InstallOptions.to_cli_options())
@multi_options(installoptions_to_cli_options())
@standard_error_handler
def install(ctx, component, preset, **kwargs):
if preset:
Expand Down
28 changes: 28 additions & 0 deletions client/cli/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from dataclasses import fields
from datetime import timedelta
from typing import Any, Dict, List, Union
from beiboot.types import InstallOptions
import click
from click import ClickException

Expand Down Expand Up @@ -221,3 +224,28 @@ def decorator(f):
return f

return decorator


def installoptions_to_cli_options() -> List[Dict[str, Union[bool, str, Any, None]]]:
result = []
for _field in fields(InstallOptions):
if _field.name in ["max_session_timeout", "max_lifetime"]:
_data = dict(
name=_field.name,
long=_field.name.replace("_", "-"),
short=_field.metadata.get("short"),
required=False,
help=_field.metadata.get("help"),
type=TimeDelta(name=_field.name),
)
else:
_data = dict(
name=_field.name,
long=_field.name.replace("_", "-"),
short=_field.metadata.get("short"),
required=False,
help=_field.metadata.get("help"),
type=_field.metadata.get("type") or "string",
)
result.append(_data)
return result