Skip to content

Commit a59202c

Browse files
Print warning for deprecated CLI options (#562)
1 parent a08a819 commit a59202c

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

janus_core/cli/geomopt.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
Tracker,
2424
WriteKwargs,
2525
)
26-
from janus_core.cli.utils import yaml_converter_callback
26+
from janus_core.cli.utils import deprecated_option, yaml_converter_callback
2727

2828
app = Typer()
2929

@@ -127,7 +127,12 @@ def geomopt(
127127
] = None,
128128
filter_func: Annotated[
129129
str | None,
130-
Option(help="Deprecated. Please use --filter", rich_help_panel="Calculation"),
130+
Option(
131+
help="Deprecated. Please use --filter",
132+
rich_help_panel="Calculation",
133+
callback=deprecated_option,
134+
hidden=True,
135+
),
131136
] = None,
132137
pressure: Annotated[
133138
float,

janus_core/cli/types.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from click import Choice
1010
from typer import Option
1111

12+
from janus_core.cli.utils import deprecated_option
1213
from janus_core.helpers.janus_types import Architectures, Devices
1314

1415
if TYPE_CHECKING:
@@ -101,7 +102,12 @@ def __str__(self) -> str:
101102
]
102103
ModelPath = Annotated[
103104
str | None,
104-
Option(help="Deprecated. Please use --model", rich_help_panel="MLIP calculator"),
105+
Option(
106+
help="Deprecated. Please use --model",
107+
rich_help_panel="MLIP calculator",
108+
callback=deprecated_option,
109+
hidden=True,
110+
),
105111
]
106112

107113
FilePrefix = Annotated[

janus_core/cli/utils.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
from pathlib import Path
1010
from typing import TYPE_CHECKING, Any
1111

12+
from typer import CallbackParam, secho
13+
from typer.colors import YELLOW
1214
from typer_config import conf_callback_factory, yaml_loader
1315
import yaml
1416

@@ -409,3 +411,25 @@ def parse_correlation_kwargs(kwargs: CorrelationKwargs) -> list[dict]:
409411

410412
parsed_kwargs.append(cor_kwargs)
411413
return parsed_kwargs
414+
415+
416+
# Callback to print warning for deprecated options
417+
def deprecated_option(param: CallbackParam, value: Any):
418+
"""
419+
Print warning for deprecated option.
420+
421+
Parameters
422+
----------
423+
param
424+
Callback parameters from typer.
425+
value
426+
Value of parameter.
427+
428+
Returns
429+
-------
430+
Any
431+
Unmodified parameter value.
432+
"""
433+
if value:
434+
secho(f"Warning: --{param.name} is deprecated.", fg=YELLOW)
435+
return value

0 commit comments

Comments
 (0)