8000 docs(cli): add PyYAML requirement notice · DylanGraham/python-gitlab@d29a489 · GitHub
[go: up one dir, main page]

Skip to content

Commit d29a489

Browse files
committed
docs(cli): add PyYAML requirement notice
Fixes python-gitlab#606
1 parent 6585c96 commit d29a489

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

docs/cli.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,11 @@ These options must be defined before the mandatory arguments.
157157
``--output``, ``-o``
158158
Output format. Defaults to a custom format. Can also be ``yaml`` or ``json``.
159159

160+
**Notice:**
161+
162+
The `PyYAML package <https://pypi.org/project/PyYAML/>`_ is required to use the yaml output option.
163+
You need to install it separately using ``pip install PyYAML``
164+
160165
``--fields``, ``-f``
161166
Comma-separated list of fields to display (``yaml`` and ``json`` output
162167
formats only). If not used, all the object fields are displayed.

gitlab/v4/cli.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -302,14 +302,24 @@ def display_list(self, data, fields, **kwargs):
302302

303303
class YAMLPrinter(object):
304304
def display(self, d, **kwargs):
305-
import yaml # noqa
306-
print(yaml.safe_dump(d, default_flow_style=False))
305+
try:
306+
import yaml # noqa
307+
print(yaml.safe_dump(d, default_flow_style=False))
308+
except ImportError:
309+
exit("PyYaml is not installed.\n"
310+
"Install it with `pip install PyYaml` "
311+
"to use the yaml output feature")
307312

308313
def display_list(self, data, fields, **kwargs):
309-
import yaml # noqa
310-
print(yaml.safe_dump(
311-
[get_dict(obj, fields) for obj in data],
312-
default_flow_style=False))
314+
try:
315+
import yaml # noqa
316+
print(yaml.safe_dump(
317+
[get_dict(obj, fields) for obj in data],
318+
default_flow_style=False))
319+
except ImportError:
320+
exit("PyYaml is not installed.\n"
321+
"Install it with `pip install PyYaml` "
322+
"to use the yaml output feature")
313323

314324

315325
class LegacyPrinter(object):

0 commit comments

Comments
 (0)
0