| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 1cf5932 commit 005ba93
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -50,6 +50,23 @@ | |||
| 50 | 50 | __F = TypeVar("__F", bound=Callable[..., Any]) | |
| 51 | 51 | ||
| 52 | 52 | ||
| 53 | + class VerticalHelpFormatter(argparse.HelpFormatter): | ||
| 54 | + def format_help(self) -> str: | ||
| 55 | + result = super().format_help() | ||
| 56 | + output = "" | ||
| 57 | + indent = self._indent_increment * " " | ||
| 58 | + for line in result.splitlines(keepends=True): | ||
| 59 | + # All of our resources are on one line and wrapped inside braces. | ||
| 60 | + # For example: {application,resource1,resource2} | ||
| 61 | + # We then put each resource on its own line to make it easier to read. | ||
| 62 | + if line.strip().startswith("{"): | ||
| 63 | + choices = line.strip().strip("{}").split(",") | ||
| 64 | + choices_str = f"\n{indent}".join(choices) | ||
| 65 | + line = f"{indent}{choices_str}\n" | ||
| 66 | + output += line | ||
| 67 | + return output | ||
| 68 | + | ||
| 69 | + | ||
| 53 | 70 | def register_custom_action( | |
| 54 | 71 | cls_names: Union[str, Tuple[str, ...]], | |
| 55 | 72 | mandatory: Tuple[str, ...] = (), | |
@@ -110,6 +127,7 @@ def _get_base_parser(add_help: bool = True) -> argparse.ArgumentParser: | |||
| 110 | 127 | parser = argparse.ArgumentParser( | |
| 111 | 128 | add_help=add_help, | |
| 112 | 129 | description="GitLab API Command Line Interface", | |
| 130 | + formatter_class=VerticalHelpFormatter, | ||
| 113 | 131 | allow_abbrev=False, | |
| 114 | 132 | ) | |
| 115 | 133 | parser.add_argument("--version", help="Display the version.", action="store_true") | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -377,7 +377,9 @@ def extend_parser(parser: argparse.ArgumentParser) -> argparse.ArgumentParser: | |||
| 377 | 377 | ||
| 378 | 378 | for cls in sorted(classes, key=operator.attrgetter("__name__")): | |
| 379 | 379 | arg_name = cli.cls_to_gitlab_resource(cls) | |
| 380 | - object_group = subparsers.add_parser(arg_name) | ||
| 380 | + object_group = subparsers.add_parser( | ||
| 381 | + arg_name, formatter_class=cli.VerticalHelpFormatter | ||
| 382 | + ) | ||
| 381 | 383 | ||
| 382 | 384 | object_subparsers = object_group.add_subparsers( | |
| 383 | 385 | title="action", | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -34,6 +34,18 @@ def test_config_error_with_help_prints_help(script_runner): | |||
| 34 | 34 | assert ret.returncode == 0 | |
| 35 | 35 | ||
| 36 | 36 | ||
| 37 | + def test_global_help_prints_resources_vertically(script_runner): | ||
| 38 | + ret = script_runner.run("gitlab", "--help") | ||
| 39 | + assert """resource:\n application\n application-appearance\n""" in ret.stdout | ||
| 40 | + assert ret.returncode == 0 | ||
| 41 | + | ||
| 42 | + | ||
| 43 | + def test_resource_help_prints_actions_vertically(script_runner): | ||
| 44 | + ret = script_runner.run("gitlab", "project", "--help") | ||
| 45 | + assert """action:\n list\n get""" in ret.stdout | ||
| 46 | + assert ret.returncode == 0 | ||
| 47 | + | ||
| 48 | + | ||
| 37 | 49 | @pytest.mark.script_launch_mode("inprocess") | |
| 38 | 50 | @responses.activate | |
| 39 | 51 | def test_defaults_to_gitlab_com(script_runner, resp_get_project, monkeypatch): | |
| Back | FazBrowse Home | New Git URL |
0 commit comments