Skip to content

Commit

Permalink
updated deprecations classes
Browse files Browse the repository at this point in the history
Signed-off-by: Ahmad Wahid <ahmedwahid16101@gmail.com>
  • Loading branch information
Ahmad-Wahid committed Jan 17, 2024
1 parent f4015cd commit fff3d95
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions flexmeasures/cli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from typing import Any
from datetime import datetime, timedelta

import warnings
import click
import pytz
from click_default_group import DefaultGroup
Expand All @@ -29,7 +28,13 @@ class MsgStyle(object):


class DeprecatedOption(click.Option):
"""A custom option that can be used to mark an option as deprecated."""
"""A custom option that can be used to mark an option as deprecated.
References
----------------
Copied from https://stackoverflow.com/a/50402799/13775459
"""

def __init__(self, *args, **kwargs):
self.deprecated = kwargs.pop("deprecated", ())
Expand All @@ -38,7 +43,13 @@ def __init__(self, *args, **kwargs):


class DeprecatedOptionsCommand(click.Command):
"""A custom command that can be used to mark options as deprecated."""
"""A custom command that can be used to mark options as deprecated.
References
----------------
Adopted from https://stackoverflow.com/a/50402799/13775459
"""

def make_parser(self, ctx):
"""Hook 'make_parser' and during processing check the name
Expand Down Expand Up @@ -77,8 +88,10 @@ def process(value, state):
del frame

if opt in deprecated:
msg = "Option '{}' will be replaced by '{}'."
warnings.warn(msg.format(opt, preferred), FutureWarning)
click.secho(
f"Option '{opt}' will be replaced by '{preferred}'.",
**MsgStyle.WARN,
)
return orig_process(value, state)

return process
Expand Down

0 comments on commit fff3d95

Please sign in to comment.