33import pytest
44
55from interfacy import CommandGroup
6- from interfacy .appearance .layouts import ArgparseLayout
6+ from interfacy .appearance .layouts import ArgparseLayout , StandardLayout
77from interfacy .argparse_backend import Argparser
88from interfacy .exceptions import ConfigurationError
99
@@ -24,6 +24,14 @@ def cmd_init() -> None:
2424 """Initialize a repository."""
2525
2626
27+ def cmd_push () -> None :
28+ """Push changes."""
29+
30+
31+ def cmd_pull () -> None :
32+ """Pull changes."""
33+
34+
2735@pytest .mark .parametrize ("parser" , ["argparse_req_pos" , "click_req_pos" ], indirect = True )
2836def test_root_help_groups_commands_before_ungrouped (parser , capsys ) -> None :
2937 parser .add_command (cmd_status , name = "status" )
@@ -53,6 +61,48 @@ def test_root_help_groups_commands_before_ungrouped(parser, capsys) -> None:
5361 assert init_idx < status_idx
5462
5563
64+ @pytest .mark .parametrize ("parser" , ["argparse_req_pos" , "click_req_pos" ], indirect = True )
65+ def test_help_group_command_indent_is_configurable (parser , capsys ) -> None :
66+ parser .apply_setup (help_layout = StandardLayout (command_indent = 5 ))
67+ parser .add_command (cmd_clone , name = "clone" , help_group = "setup" )
68+ parser .add_command (cmd_status , name = "status" )
69+
70+ result = parser .run (args = ["--help" ])
71+ assert isinstance (result , SystemExit )
72+ assert result .code == 0
73+
74+ captured = capsys .readouterr ()
75+ combined = _strip_ansi (captured .out + captured .err )
76+ lines = combined .splitlines ()
77+
78+ assert any (line .startswith (" clone" ) for line in lines )
79+
80+
81+ @pytest .mark .parametrize ("parser" , ["argparse_req_pos" , "click_req_pos" ], indirect = True )
82+ def test_help_group_spacing_is_configurable (parser , capsys ) -> None :
83+ parser .apply_setup (help_layout = StandardLayout (command_group_spacing = 0 ))
84+ parser .add_command (cmd_clone , name = "clone" , help_group = "setup" )
85+ parser .add_command (cmd_push , name = "push" , help_group = "sync" )
86+ parser .add_command (cmd_pull , name = "pull" )
87+
88+ result = parser .run (args = ["--help" ])
89+ assert isinstance (result , SystemExit )
90+ assert result .code == 0
91+
92+ captured = capsys .readouterr ()
93+ combined = _strip_ansi (captured .out + captured .err )
94+ lines = combined .splitlines ()
95+ clone_idx = next (idx for idx , line in enumerate (lines ) if line .strip ().startswith ("clone" ))
96+ sync_idx = lines .index ("sync" )
97+ push_idx = next (idx for idx , line in enumerate (lines ) if line .strip ().startswith ("push" ))
98+ pull_idx = next (idx for idx , line in enumerate (lines ) if line .strip ().startswith ("pull" ))
99+
100+ assert lines [clone_idx + 1 ] == "sync"
101+ assert lines [push_idx + 1 ].lstrip ().startswith ("pull" )
102+ assert sync_idx == clone_idx + 1
103+ assert pull_idx == push_idx + 1
104+
105+
56106@pytest .mark .parametrize ("backend" , ["argparse" , "click" ])
57107def test_nested_help_groups_render_with_adaptive_layout (backend : str , capsys ) -> None :
58108 if backend == "click" :
0 commit comments