Skip to content

Commit 70480ab

Browse files
committed
Attempt at a compromise format that is split over 2 lines
New format looks like: ```sh myapp> set allow_style always allow_style: 'Terminal' -> 'Always' ``` Where "'Terminal'" is red and "'Always'" is green. This is still more abbreviated than the original format, but not as abbreviated as putting everything on one line. Moreover, it preserves the more colorful diff-style display and the switch to using pfeedback.
1 parent 7287681 commit 70480ab

3 files changed

Lines changed: 13 additions & 7 deletions

File tree

cmd2/cmd2.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4732,7 +4732,9 @@ def do_set(self, args: argparse.Namespace) -> None:
47324732
args.param,
47334733
": ",
47344734
(f"{orig_value!r}", "red"),
4735-
" -> ",
4735+
"\n",
4736+
" " * max(0, len(args.param) - 1),
4737+
"-> ",
47364738
(f"{settable.value!r}", "green"),
47374739
)
47384740
self.pfeedback(feedback_msg)

tests/test_cmd2.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,8 @@ def test_set_with_choices(base_app) -> None:
273273
out, err = run_cmd(base_app, f"set fake {fake_choices[1]}")
274274
assert base_app.last_result is True
275275
assert not out
276-
assert err == [f"fake: {fake_choices[0]!r} -> {fake_choices[1]!r}"]
276+
assert err[0].startswith(f"fake: {fake_choices[0]!r}")
277+
assert err[1].endswith(f"-> {fake_choices[1]!r}")
277278

278279
# Try an invalid choice
279280
_out, err = run_cmd(base_app, "set fake bad_value")
@@ -892,12 +893,13 @@ def test_base_timing(base_app) -> None:
892893
base_app.feedback_to_output = False
893894
out, err = run_cmd(base_app, "set timing True")
894895
assert not out
895-
assert err[0] == "timing: False -> True"
896+
assert err[0].startswith("timing: False")
897+
assert err[1].endswith("-> True")
896898

897899
if sys.platform == "win32":
898-
assert err[1].startswith("Elapsed: 0:00:00")
900+
assert err[2].startswith("Elapsed: 0:00:00")
899901
else:
900-
assert err[1].startswith("Elapsed: 0:00:00.0")
902+
assert err[2].startswith("Elapsed: 0:00:00.0")
901903

902904

903905
def test_base_debug(base_app) -> None:
@@ -912,7 +914,8 @@ def test_base_debug(base_app) -> None:
912914
# Set debug true
913915
out, err = run_cmd(base_app, "set debug True")
914916
assert not out
915-
assert err == ["debug: False -> True"]
917+
assert err[0].startswith("debug: False")
918+
assert err[1].endswith("-> True")
916919

917920
# Verify that we now see the exception traceback
918921
out, err = run_cmd(base_app, "edit")

tests/test_commandset.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1104,7 +1104,8 @@ def __init__(self) -> None:
11041104
# change the value and verify the value changed
11051105
out, err = run_cmd(app, "set arbitrary_value 10")
11061106
assert not out
1107-
assert err == ["arbitrary_value: 5 -> 10"]
1107+
assert err[0].startswith("arbitrary_value: 5")
1108+
assert err[1].endswith("-> 10")
11081109
out, err = run_cmd(app, "set arbitrary_value")
11091110
any("arbitrary_value" in line and "10" in line for line in out)
11101111

0 commit comments

Comments
 (0)