Skip to content

Commit

Permalink
Merge pull request #390 from gboutry/feat/remove-deprecated-parameters
Browse files Browse the repository at this point in the history
Remove deprecated parameters
  • Loading branch information
javacruft authored Dec 20, 2024
2 parents f285a26 + 37ad747 commit f7f7bca
Show file tree
Hide file tree
Showing 10 changed files with 14 additions and 81 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-snap.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ jobs:
sg snap_daemon "openstack.sunbeam enable orchestration"
sg snap_daemon "openstack.sunbeam enable loadbalancer"
sg snap_daemon "openstack.sunbeam enable dns --nameservers=testing.github."
sg snap_daemon "openstack.sunbeam enable dns testing.github."
sg snap_daemon "openstack.sunbeam disable dns"
sg snap_daemon "openstack.sunbeam disable loadbalancer"
sg snap_daemon "openstack.sunbeam disable orchestration"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-snap.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ jobs:
sg snap_daemon "sunbeam launch"
sg snap_daemon "sunbeam enable orchestration"
sg snap_daemon "sunbeam enable loadbalancer"
sg snap_daemon "sunbeam enable dns --nameservers=testing.github."
sg snap_daemon "sunbeam enable dns testing.github."
sg snap_daemon "sunbeam enable telemetry"
sg snap_daemon "sunbeam enable observability"
sg snap_daemon "sunbeam enable vault --dev-mode"
Expand Down
3 changes: 1 addition & 2 deletions sunbeam-python/sunbeam/commands/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
from sunbeam.core.common import FORMAT_TABLE, FORMAT_YAML
from sunbeam.core.deployment import Deployment
from sunbeam.core.manifest import Manifest, SoftwareConfig
from sunbeam.utils import argument_with_deprecated_option

if typing.TYPE_CHECKING:
from sunbeam.features.interface.v1.base import BaseFeature
Expand Down Expand Up @@ -138,7 +137,7 @@ def list_manifests(ctx: click.Context, format: str) -> None:


@click.command()
@argument_with_deprecated_option("id", type=str, help="Manifest ID")
@click.argument("id", type=str)
@click.pass_context
def show(ctx: click.Context, id: str) -> None:
"""Show Manifest data.
Expand Down
5 changes: 1 addition & 4 deletions sunbeam-python/sunbeam/commands/plans.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
FORMAT_YAML,
)
from sunbeam.core.deployment import Deployment
from sunbeam.utils import argument_with_deprecated_option

LOG = logging.getLogger(__name__)
console = Console()
Expand Down Expand Up @@ -74,9 +73,7 @@ def list_plans(ctx: click.Context, format: str):


@plans.command("unlock")
@argument_with_deprecated_option(
"plan", type=str, help="Name of the terraform plan to unlock."
)
@click.argument("plan", type=str)
@click.option("--force", is_flag=True, default=False, help="Force unlock the plan.")
@click.pass_context
def unlock_plan(ctx: click.Context, plan: str, force: bool):
Expand Down
4 changes: 2 additions & 2 deletions sunbeam-python/sunbeam/features/dns/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ This feature provides a DNS service for Sunbeam. It's based on [Designate](https
To enable the DNS service, you need an already bootstraped Sunbeam instance. Then, you can install the feature with:

```bash
sunbeam enable dns --nameservers="<ns records>"
sunbeam enable dns "<ns records>"
```

## Contents
Expand All @@ -22,7 +22,7 @@ Services are constituted of charms, i.e. operator code, and ROCKs, the correspon

## Configuration

The NS records you pass to the `--nameservers` must be a fully qualified domain name ending with a dot.
The NS records you pass to the `nameservers` must be a fully qualified domain name ending with a dot.
It must redirect towards the IP address of the bind instance. See [#commands](#commands) to retrieve the address of the bind instance.

## Commands
Expand Down
11 changes: 1 addition & 10 deletions sunbeam-python/sunbeam/features/dns/feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
TerraformPlanLocation,
)
from sunbeam.utils import (
argument_with_deprecated_option,
click_option_show_hints,
pass_method_obj,
)
Expand Down Expand Up @@ -190,15 +189,7 @@ def get_database_charm_processes(self) -> dict[str, dict[str, int]]:
}

@click.command()
@argument_with_deprecated_option(
"nameservers",
type=str,
help="""\
Space delimited list of nameservers. These are the nameservers that
have been provided to the domain registrar in order to delegate
the domain to DNS service. e.g. "ns1.example.com. ns2.example.com."
""",
)
@click.argument("nameservers", type=str)
@click_option_show_hints
@pass_method_obj
def enable_cmd(
Expand Down
5 changes: 1 addition & 4 deletions sunbeam-python/sunbeam/features/pro/feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
)
from sunbeam.features.interface.v1.base import EnableDisableFeature
from sunbeam.utils import (
argument_with_deprecated_option,
click_option_show_hints,
pass_method_obj,
)
Expand Down Expand Up @@ -258,9 +257,7 @@ def run_disable_plans(self, deployment: Deployment, show_hints: bool):

@click.command()
@pass_method_obj
@argument_with_deprecated_option(
"token", type=str, short_form="t", help="Ubuntu Pro token"
)
@click.argument("token", type=str)
@click_option_show_hints
def enable_cmd(self, deployment: Deployment, token: str, show_hints: bool) -> None:
"""Enable Ubuntu Pro across deployment.
Expand Down
7 changes: 3 additions & 4 deletions sunbeam-python/sunbeam/provider/local/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@
)
from sunbeam.utils import (
CatchGroup,
argument_with_deprecated_option,
click_option_show_hints,
)

Expand Down Expand Up @@ -677,7 +676,7 @@ def _write_to_file(token: str, output: Path):


@click.command()
@argument_with_deprecated_option("name", type=str, help="Fully qualified node name.")
@click.argument("name", type=str)
@click.option(
"-f",
"--format",
Expand Down Expand Up @@ -752,7 +751,7 @@ def add(


@click.command()
@argument_with_deprecated_option("token", type=str, help="Join token.")
@click.argument("token", type=str)
@click.option("-a", "--accept-defaults", help="Accept all defaults.", is_flag=True)
@click.option(
"--role",
Expand Down Expand Up @@ -956,7 +955,7 @@ def list_nodes(
help=("Skip safety checks and ignore cleanup errors for some tasks"),
is_flag=True,
)
@argument_with_deprecated_option("name", type=str, help="Fully qualified node name.")
@click.argument("name", type=str)
@click_option_show_hints
@click.pass_context
def remove(ctx: click.Context, name: str, force: bool, show_hints: bool) -> None:
Expand Down
7 changes: 3 additions & 4 deletions sunbeam-python/sunbeam/provider/maas/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@
from sunbeam.utils import (
CatchGroup,
DefaultableMappingParameter,
argument_with_deprecated_option,
click_option_show_hints,
)

Expand Down Expand Up @@ -865,9 +864,9 @@ def list_nodes(ctx: click.Context, format: str, show_hints: bool) -> None:


@click.command("maas")
@argument_with_deprecated_option("name", type=str, help="Name of the deployment")
@argument_with_deprecated_option("token", type=str, help="API token")
@argument_with_deprecated_option("url", type=str, help="API URL")
@click.argument("name", type=str)
@click.argument("token", type=str)
@click.argument("url", type=str)
@click_option_show_hints
def add_maas(name: str, token: str, url: str, show_hints: bool) -> None:
"""Add MAAS-backed deployment to registered deployments."""
Expand Down
49 changes: 0 additions & 49 deletions sunbeam-python/sunbeam/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,55 +328,6 @@ def first_connected_server(servers: list) -> str | None:
return None


def argument_with_deprecated_option(
name: str,
type=str,
help: str | None = None,
short_form: str | None = None,
**kwargs,
):
"""Decorator to create an argument with a deprecated option."""
option_name = name + "_option"

def callback(ctx: click.Context, param: click.Parameter, argument_value):
"""Swap option value from option to argument."""
option_value = ctx.params.pop(option_name, None)
if option_value is not None:
if argument_value:
raise click.UsageError(
f"{name} cannot be used as both an option and an argument,"
" use argument."
)
# Set the value of the argument by the option value
return option_value
return argument_value

def decorator(func: click.decorators.FC) -> click.decorators.FC:
arg_def = click.argument(
name,
type=type,
required=False,
callback=callback,
**kwargs,
)
option: tuple[str, str] | tuple[str]
if short_form:
option = (f"-{short_form}", f"--{name}")
else:
option = (f"--{name}",)
option_def = click.option(
*option,
option_name,
# This is the key to make the option processed before argument
is_eager=True,
help=(help + ". Deprecated, use argument instead" if help else None),
**kwargs,
)
return arg_def(option_def(func))

return decorator


def click_option_show_hints(func: click.decorators.FC) -> click.decorators.FC:
"""Common decorator to show hints for questions."""
return click.option(
Expand Down

0 comments on commit f7f7bca

Please sign in to comment.