| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent e15349c commit b22d662
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,6 +3,7 @@ | |||
| 3 | 3 | import os | |
| 4 | 4 | import re | |
| 5 | 5 | import sys | |
| 6 | + import textwrap | ||
| 6 | 7 | from types import ModuleType | |
| 7 | 8 | from typing import ( | |
| 8 | 9 | Any, | |
@@ -50,11 +51,21 @@ def format_help(self) -> str: | |||
| 50 | 51 | for line in result.splitlines(keepends=True): | |
| 51 | 52 | # All of our resources are on one line and wrapped inside braces. | |
| 52 | 53 | # For example: {application,resource1,resource2} | |
| 54 | + # except if there are fewer resources - then the line and help text | ||
| 55 | + # are collapsed on the same line. | ||
| 56 | + # For example: {list} Action to execute on the GitLab resource. | ||
| 53 | 57 | # We then put each resource on its own line to make it easier to read. | |
| 54 | 58 | if line.strip().startswith("{"): | |
| 55 | - choices = line.strip().strip("{}").split(",") | ||
| 56 | - choices_str = f"\n{indent}".join(choices) | ||
| 57 | - line = f"{indent}{choices_str}\n" | ||
| 59 | + choice_string, help_string = line.split("}", 1) | ||
| 60 | + choice_list = choice_string.strip(" {").split(",") | ||
| 61 | + help_string = help_string.strip() | ||
| 62 | + | ||
| 63 | + if help_string: | ||
| 64 | + help_indent = len(max(choice_list, key=len)) * " " | ||
| 65 | + choice_list.append(f"{help_indent} {help_string}") | ||
| 66 | + | ||
| 67 | + choices = "\n".join(choice_list) | ||
| 68 | + line = f"{textwrap.indent(choices, indent)}\n" | ||
| 58 | 69 | output += line | |
| 59 | 70 | return output | |
| 60 | 71 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -46,6 +46,12 @@ def test_resource_help_prints_actions_vertically(script_runner): | |||
| 46 | 46 | assert ret.returncode == 0 | |
| 47 | 47 | ||
| 48 | 48 | ||
| 49 | + def test_resource_help_prints_actions_vertically_only_one_action(script_runner): | ||
| 50 | + ret = script_runner.run(["gitlab", "event", "--help"]) | ||
| 51 | + assert """action:\n list\n""" in ret.stdout | ||
| 52 | + assert ret.returncode == 0 | ||
| 53 | + | ||
| 54 | + | ||
| 49 | 55 | @pytest.mark.script_launch_mode("inprocess") | |
| 50 | 56 | @responses.activate | |
| 51 | 57 | def test_defaults_to_gitlab_com(script_runner, resp_get_project, monkeypatch): | |
| Back | FazBrowse Home | New Git URL |
0 commit comments