Skip to content

Commit

Permalink
docs: add script to generate cli api docs
Browse files Browse the repository at this point in the history
  • Loading branch information
mvidalgarcia committed Apr 16, 2020
1 parent e2eb481 commit 44811f7
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,7 @@ target/

# Visual Studio Code files
.vscode/*

# Docs autogeneration
cmd_list.txt
cli_api.md
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ recursive-include docs *.py
recursive-include docs *.png
recursive-include docs *.rst
recursive-include tests *.py
recursive-include scripts *.py
13 changes: 12 additions & 1 deletion run-tests.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
#!/bin/sh
#!/bin/bash
#
# This file is part of REANA.
# Copyright (C) 2017, 2018 CERN.
#
# REANA is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.


cli_docs_url=https://raw.githubusercontent.com/reanahub/docs.reana.io/master/docs/reference/reana-client-cli-api/index.md
docs_differ_error_msg='Current reana-client differs with the documentation. Please update http://docs.reana.io/reference/reana-client-cli-api/.'
python_version=$(python -c 'import sys; print(sys.version_info.major)')

pydocstyle reana_client && \
isort -rc -c -df **/*.py && \
reana-client --help > cmd_list.txt && \
diff -q -w docs/cmd_list.txt cmd_list.txt && \
rm cmd_list.txt && \
if [ "$python_version" -eq 3 ]
then
python scripts/generate_cli_api.py > cli_api.md && \
(diff -q -w cli_api.md <(curl -s $cli_docs_url) || (echo $docs_differ_error_msg && exit 1)) && \
rm cli_api.md
fi
check-manifest --ignore ".travis-*" && \
sphinx-build -qnNW docs docs/_build/html && \
python setup.py test && \
Expand Down
35 changes: 35 additions & 0 deletions scripts/generate_cli_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# -*- coding: utf-8 -*-
#
# This file is part of REANA.
# Copyright (C) 2020 CERN.
#
# REANA is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.
"""REANA client CLI API docs generation."""

import click

from reana_client.cli import cli


def _print_code_block(content, lang=''):
print('```{}'.format(lang))
print(content)
print('```')


def generate_cli_docs():
"""Generate Markdown friendly CLI API documentation."""
print('# reana-client CLI API\n')
with click.Context(cli) as ctx:
_print_code_block(cli.get_help(ctx), lang='console')

for cmd_group in cli.cmd_groups:
print('\n## {}'.format(cmd_group.help))
for cmd_obj in cmd_group.commands.values():
print('\n### {}\n'.format(cmd_obj.name))
print(cmd_obj.help)


if __name__ == "__main__":
generate_cli_docs()

0 comments on commit 44811f7

Please sign in to comment.