diff --git a/requirements.txt b/requirements.txt index 5813688..228b8d4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ pytest==8.4.1 pytest-cov==6.2.1 pdoc==15.0.4 -flake8==7.3.0 \ No newline at end of file +flake8==7.3.0 +pdoc==15.0.4 \ No newline at end of file diff --git a/stat_log_db/pyproject.toml b/stat_log_db/pyproject.toml index df2a999..efd8321 100644 --- a/stat_log_db/pyproject.toml +++ b/stat_log_db/pyproject.toml @@ -15,7 +15,8 @@ dependencies = [ dev = [ "pytest==8.4.1", "pytest-cov==6.2.1", - "flake8==7.3.0" + "flake8==7.3.0", + "pdoc==15.0.4" ] [project.scripts] diff --git a/tests/test_tools.py b/tests/test_tools.py index 60612b5..dff7a15 100644 --- a/tests/test_tools.py +++ b/tests/test_tools.py @@ -193,6 +193,19 @@ def test_test_style(): assert "Running style tests" in out assert "flake8" in out +# def test_doc_generate_html(): +# """Test -d h (generate HTML documentation).""" +# code, out = run_tools(['-d', 'h']) +# assert code == 0 +# assert 'Generating HTML documentation' in out + + +def test_doc_invalid_arg(): + """Test -d with invalid argument.""" + code, out = run_tools(['-d', 'x']) + assert code == 1 + assert ("Unsupported argument" in out) or ("Invalid doc mode" in out) + @pytest.mark.skipif(GITHUB_ACTIONS, reason="Skipping test on GitHub Actions") def test_clean(): diff --git a/tools.sh b/tools.sh index 19f2e9f..024a2f4 100755 --- a/tools.sh +++ b/tools.sh @@ -5,10 +5,12 @@ supported_installation_opts="d n" install="" uninstall=0 clean=0 +supported_doc_opts="h s" +doc="" supported_test_opts="p t a d s" test="" -while getopts ":i:t:chu" flag; do +while getopts ":i:t:d:chu" flag; do case "${flag}" in i) if [[ " $supported_installation_opts " =~ " $OPTARG " ]]; then install="$OPTARG" @@ -24,6 +26,12 @@ while getopts ":i:t:chu" flag; do echo "Unsupported argument '$OPTARG' for '-$flag'. Please specify one of: $supported_test_opts" >&2 && exit 1; fi ;; + d) if [[ " $supported_doc_opts " =~ " $OPTARG " ]]; then + doc="$OPTARG" + else + echo "Unsupported argument '$OPTARG' for '-$flag'. Please specify one of: $supported_doc_opts" >&2 && exit 1; + fi + ;; h) cat README.md && exit 0;; :) echo "Option -$OPTARG requires an argument" >&2; exit 1;; @@ -80,6 +88,27 @@ if [ -n "$test" ]; then esac fi +# Documentation [-d] +if [ -n "$doc" ]; then + case "$doc" in + h) + echo "Generating HTML documentation..." + if [ ! -d "stat_log_db/docs" ]; then + mkdir -p stat_log_db/docs + fi + pdoc --output-dir stat_log_db/docs stat_log_db + ;; + s) + echo "Hosting documentation..." + pdoc stat_log_db --host localhost + ;; + *) + echo "Invalid doc mode '$doc'. Use one of: $supported_doc_opts" >&2 + exit 1 + ;; + esac +fi + # Clean artifacts [-c] if [ $clean -eq 1 ]; then echo "Cleaning up workspace..."