Skip to content

Commit 56e5317

Browse files
author
Alon Yeshurun
committed
Update
1 parent dc276c9 commit 56e5317

4 files changed

Lines changed: 61 additions & 18 deletions

File tree

src/fabric_cli/commands/config/fab_config_get.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,19 @@ def exec_command(args: Namespace) -> None:
1515
# Backward compatibility: 'mode' is no longer a configurable setting.
1616
# Phase 1: warn but still return the runtime mode so existing scripts don't break.
1717
if key == fab_constant.FAB_MODE:
18-
utils_ui.print_warning(
19-
"The 'mode' setting is deprecated and will be removed in a future release. "
20-
"Run 'fab' without arguments to enter REPL mode, "
21-
"or use 'fab <command>' for command-line mode."
22-
)
2318
from fabric_cli.core.fab_context import Context
2419

25-
utils_ui.print_output_format(args, data=Context().get_runtime_mode())
20+
runtime_mode = Context().get_runtime_mode()
21+
msg = "The 'mode' setting is deprecated. "
22+
if runtime_mode == fab_constant.FAB_MODE_INTERACTIVE:
23+
msg += "Run 'exit' to leave the REPL, then use 'fab <command>' for command-line mode."
24+
else:
25+
msg += (
26+
"Run 'fab' without arguments to enter REPL mode, "
27+
"or use 'fab <command>' for command-line mode."
28+
)
29+
utils_ui.print_warning(msg)
30+
utils_ui.print_output_format(args, data=runtime_mode)
2631
return
2732

2833
if key not in fab_constant.FAB_CONFIG_KEYS_TO_VALID_VALUES:

src/fabric_cli/commands/config/fab_config_set.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,17 @@ def exec_command(args: Namespace) -> None:
2121
# Backward compatibility: 'mode' is no longer a configurable setting.
2222
# Phase 1: warn but still honour the request so existing scripts don't break.
2323
if key == fab_constant.FAB_MODE:
24-
utils_ui.print_warning(
25-
"The 'mode' setting is deprecated and will be removed in a future release. "
26-
"Run 'fab' without arguments to enter REPL mode, "
27-
"or use 'fab <command>' for command-line mode."
28-
)
24+
from fabric_cli.core.fab_context import Context
25+
26+
msg = "The 'mode' setting is deprecated. "
27+
if Context().get_runtime_mode() == fab_constant.FAB_MODE_INTERACTIVE:
28+
msg += "Run 'exit' to leave the REPL, then use 'fab <command>' for command-line mode."
29+
else:
30+
msg += (
31+
"Run 'fab' without arguments to enter REPL mode, "
32+
"or use 'fab <command>' for command-line mode."
33+
)
34+
utils_ui.print_warning(msg)
2935
if value == fab_constant.FAB_MODE_INTERACTIVE:
3036
from fabric_cli.core.fab_interactive import start_interactive_mode
3137

src/fabric_cli/core/fab_output.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import json
55
from argparse import Namespace
6-
from datetime import datetime
6+
from datetime import datetime, timezone
77
from enum import Enum
88
from typing import Any, Dict, List, Optional, cast
99

@@ -96,7 +96,7 @@ def __init__(
9696
The data parameter is always converted to a list format internally.
9797
Error codes are only included in the output when status is Failed.
9898
"""
99-
self._timestamp = datetime.utcnow().isoformat() + "Z"
99+
self._timestamp = datetime.now(timezone.utc).isoformat().replace("+00:00", "Z")
100100
self._status = status
101101
self._command = command
102102
self._subcommand = subcommand

tests/test_commands/test_config.py

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import pytest
77

88
import fabric_cli.core.fab_constant as constant
9+
from fabric_cli.core.fab_context import Context
910
from fabric_cli.errors import ErrorMessages
1011
from tests.test_commands.commands_parser import CLIExecutor
1112
from tests.test_commands.data.static_test_data import StaticTestData
@@ -172,11 +173,16 @@ def test_config_clear_cache_success(
172173
# endregion
173174

174175

175-
DEPRECATION_WARNING = (
176-
"The 'mode' setting is deprecated and will be removed in a future release. "
176+
DEPRECATION_PREFIX = "The 'mode' setting is deprecated. "
177+
DEPRECATION_COMMANDLINE_SUFFIX = (
177178
"Run 'fab' without arguments to enter REPL mode, "
178179
"or use 'fab <command>' for command-line mode."
179180
)
181+
DEPRECATION_INTERACTIVE_SUFFIX = (
182+
"Run 'exit' to leave the REPL, then use 'fab <command>' for command-line mode."
183+
)
184+
DEPRECATION_WARNING_COMMANDLINE = DEPRECATION_PREFIX + DEPRECATION_COMMANDLINE_SUFFIX
185+
DEPRECATION_WARNING_INTERACTIVE = DEPRECATION_PREFIX + DEPRECATION_INTERACTIVE_SUFFIX
180186

181187

182188
class TestConfigModeDeprecated:
@@ -193,7 +199,7 @@ def test_config_set_mode_interactive_warns_and_launches_repl_success(
193199
"""'config set mode interactive' must warn and launch REPL."""
194200
cli_executor.exec_command(f"config set mode {constant.FAB_MODE_INTERACTIVE}")
195201

196-
mock_print_warning.assert_called_once_with(DEPRECATION_WARNING)
202+
mock_print_warning.assert_called_once_with(DEPRECATION_WARNING_INTERACTIVE)
197203
mock_repl.assert_called_once()
198204

199205
@pytest.mark.parametrize("mode_value", [
@@ -206,7 +212,20 @@ def test_config_set_mode_non_interactive_warns_without_repl_success(
206212
"""'config set mode command_line' (or bogus) must warn but not launch REPL."""
207213
cli_executor.exec_command(f"config set mode {mode_value}")
208214

209-
mock_print_warning.assert_called_once_with(DEPRECATION_WARNING)
215+
mock_print_warning.assert_called_once_with(DEPRECATION_WARNING_INTERACTIVE)
216+
mock_repl.assert_not_called()
217+
218+
def test_config_set_mode_in_commandline_warns_with_fab_hint_success(
219+
self, mock_print_warning, mock_repl, cli_executor: CLIExecutor
220+
):
221+
"""'config set mode command_line' in command-line mode must show fab hint."""
222+
Context().set_runtime_mode(constant.FAB_MODE_COMMANDLINE)
223+
try:
224+
cli_executor.exec_command(f"config set mode {constant.FAB_MODE_COMMANDLINE}")
225+
finally:
226+
Context().set_runtime_mode(constant.FAB_MODE_INTERACTIVE)
227+
228+
mock_print_warning.assert_called_once_with(DEPRECATION_WARNING_COMMANDLINE)
210229
mock_repl.assert_not_called()
211230

212231
def test_config_set_non_mode_key_still_works_success(
@@ -222,7 +241,20 @@ def test_config_get_mode_warns_and_returns_runtime_mode_success(
222241
"""'config get mode' must warn and return the runtime mode."""
223242
cli_executor.exec_command("config get mode")
224243

225-
mock_print_warning.assert_any_call(DEPRECATION_WARNING)
244+
mock_print_warning.assert_any_call(DEPRECATION_WARNING_INTERACTIVE)
245+
mock_questionary_print.assert_called()
246+
247+
def test_config_get_mode_in_commandline_warns_with_fab_hint_success(
248+
self, mock_questionary_print, mock_print_warning, cli_executor: CLIExecutor
249+
):
250+
"""'config get mode' in command-line mode must show fab hint."""
251+
Context().set_runtime_mode(constant.FAB_MODE_COMMANDLINE)
252+
try:
253+
cli_executor.exec_command("config get mode")
254+
finally:
255+
Context().set_runtime_mode(constant.FAB_MODE_INTERACTIVE)
256+
257+
mock_print_warning.assert_any_call(DEPRECATION_WARNING_COMMANDLINE)
226258
mock_questionary_print.assert_called()
227259

228260
def test_config_get_non_mode_key_still_works_success(

0 commit comments

Comments
 (0)