Skip to content

docs(cli): add PyYAML requirement notice #608

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ Documentation
The full documentation for CLI and API is available on `readthedocs
<http://python-gitlab.readthedocs.org/en/stable/>`_.

Build the docs
--------------
You can build the documentation using ``sphinx``::

pip install sphinx
python setup.py build_sphinx


Contributing
============
Expand Down
5 changes: 5 additions & 0 deletions docs/cli.rst
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,11 @@ These options must be defined before the mandatory arguments.
``--output``, ``-o``
Output format. Defaults to a custom format. Can also be ``yaml`` or ``json``.

**Notice:**

The `PyYAML package <https://pypi.org/project/PyYAML/>`_ is required to use the yaml output option.
You need to install it separately using ``pip install PyYAML``

``--fields``, ``-f``
Comma-separated list of fields to display (``yaml`` and ``json`` output
formats only). If not used, all the object fields are displayed.
Expand Down
22 changes: 16 additions & 6 deletions gitlab/v4/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,14 +302,24 @@ def display_list(self, data, fields, **kwargs):

class YAMLPrinter(object):
def display(self, d, **kwargs):
import yaml # noqa
print(yaml.safe_dump(d, default_flow_style=False))
try:
import yaml # noqa
print(yaml.safe_dump(d, default_flow_style=False))
except ImportError:
exit("PyYaml is not installed.\n"
"Install it with `pip install PyYaml` "
"to use the yaml output feature")

def display_list(self, data, fields, **kwargs):
import yaml # noqa
print(yaml.safe_dump(
[get_dict(obj, fields) for obj in data],
default_flow_style=False))
try:
import yaml # noqa
print(yaml.safe_dump(
[get_dict(obj, fields) for obj in data],
default_flow_style=False))
except ImportError:
exit("PyYaml is not installed.\n"
"Install it with `pip install PyYaml` "
"to use the yaml output feature")


class LegacyPrinter(object):
Expand Down