clinspector 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. clinspector-0.1.0/.copier-answers.yml +20 -0
  2. clinspector-0.1.0/.github/FUNDING.yml +3 -0
  3. clinspector-0.1.0/.github/copilot-instructions.md +19 -0
  4. clinspector-0.1.0/.github/dependabot.yml +9 -0
  5. clinspector-0.1.0/.github/workflows/build.yml +88 -0
  6. clinspector-0.1.0/.github/workflows/documentation.yml +57 -0
  7. clinspector-0.1.0/.gitignore +30 -0
  8. clinspector-0.1.0/.pre-commit-config.yaml +48 -0
  9. clinspector-0.1.0/LICENSE +22 -0
  10. clinspector-0.1.0/PKG-INFO +179 -0
  11. clinspector-0.1.0/README.md +121 -0
  12. clinspector-0.1.0/docs/.empty +0 -0
  13. clinspector-0.1.0/duties.py +60 -0
  14. clinspector-0.1.0/mkdocs.yml +92 -0
  15. clinspector-0.1.0/overrides/_dummy.txt +1 -0
  16. clinspector-0.1.0/pyproject.toml +229 -0
  17. clinspector-0.1.0/src/clinspector/__init__.py +5 -0
  18. clinspector-0.1.0/src/clinspector/introspect/__init__.py +51 -0
  19. clinspector-0.1.0/src/clinspector/introspect/introspect_argparse.py +62 -0
  20. clinspector-0.1.0/src/clinspector/introspect/introspect_cappa.py +84 -0
  21. clinspector-0.1.0/src/clinspector/introspect/introspect_cleo.py +120 -0
  22. clinspector-0.1.0/src/clinspector/introspect/introspect_click.py +70 -0
  23. clinspector-0.1.0/src/clinspector/introspect/introspect_typer.py +39 -0
  24. clinspector-0.1.0/src/clinspector/models/__init__.py +0 -0
  25. clinspector-0.1.0/src/clinspector/models/commandinfo.py +38 -0
  26. clinspector-0.1.0/src/clinspector/models/param.py +64 -0
  27. clinspector-0.1.0/src/clinspector/py.typed +0 -0
  28. clinspector-0.1.0/tests/__init__.py +3 -0
  29. clinspector-0.1.0/tests/conftest.py +66 -0
  30. clinspector-0.1.0/tests/test_argparse.py +15 -0
@@ -0,0 +1,20 @@
1
+ # Changes here will be overwritten by Copier
2
+ _commit: v1.5.4
3
+ _src_path: .\copier-phil65\
4
+ author_email: philipptemminghoff@googlemail.com
5
+ author_fullname: Philipp Temminghoff
6
+ author_username: phil65
7
+ copyright_date: '2024'
8
+ copyright_holder: Philipp Temminghoff
9
+ copyright_holder_email: philipptemminghoff@googlemail.com
10
+ libraries_use_qt: false
11
+ project_description: A library to parse CLI output into structured data.
12
+ project_name: CLInspector
13
+ python_minimum_version: '3.12'
14
+ python_package_command_line_name: clinspector
15
+ python_package_distribution_name: clinspector
16
+ python_package_import_name: clinspector
17
+ repository_name: clinspector
18
+ repository_namespace: phil65
19
+ repository_provider: github.com
20
+
@@ -0,0 +1,3 @@
1
+ github: phil65
2
+ custom:
3
+ - https://www.paypal.me/phil65
@@ -0,0 +1,19 @@
1
+ ## Code style
2
+
3
+ You can assume Python 3.12.
4
+ Use newest language features if possible
5
+ Consider using pattern matching, walrus operators and other new syntax features.
6
+ Adhere to pep8.
7
+
8
+ ## Tests
9
+
10
+ Tests are written using PyTest. Dont put tests into a class.
11
+
12
+ ## DocStrings
13
+
14
+ DocStrings are written in google-style.
15
+ Dont add the types to the "Args" section.
16
+ Only add a Return section if a value is returned and the meaning of the returned value
17
+ is not obvious.
18
+ You can use markdown admonitions with python-markdown syntax if neccessary (!!! info, !!! note, !!! warning).
19
+ You can use markdown tables and markdown lists if neccessary.
@@ -0,0 +1,9 @@
1
+ # Set update schedule for GitHub Actions
2
+
3
+ version: 2
4
+ updates:
5
+ - package-ecosystem: "github-actions"
6
+ directory: "/"
7
+ schedule:
8
+ # Check for updates to GitHub Actions every week
9
+ interval: "weekly"
@@ -0,0 +1,88 @@
1
+ name: Build
2
+
3
+ on: [push, pull_request]
4
+
5
+ jobs:
6
+ test:
7
+ runs-on: ${{ matrix.os }}
8
+ continue-on-error: ${{ matrix.python_version == '3.14' }}
9
+ strategy:
10
+ matrix:
11
+ python_version: ["3.12", "3.13", "3.14"]
12
+ os: ["ubuntu-latest", "macos-latest", "windows-latest"]
13
+ steps:
14
+ - name: Check out repository
15
+ uses: actions/checkout@v4
16
+
17
+ - name: Set up Python ${{ matrix.python_version }}
18
+ uses: actions/setup-python@v5
19
+ with:
20
+ python-version: ${{ matrix.python_version }}
21
+ allow-prereleases: true
22
+ - name: Install uv
23
+ uses: astral-sh/setup-uv@v3
24
+ with:
25
+ enable-cache: true
26
+ cache-dependency-glob: pyproject.toml
27
+ cache-suffix: py${{ matrix.python_version }}
28
+
29
+ - name: Install dependencies (uv sync)
30
+ run: uv sync --all-extras
31
+
32
+ - name: Check for code issues (ruff check)
33
+ uses: astral-sh/ruff-action@v1
34
+
35
+ - name: Check code format (ruff format)
36
+ uses: astral-sh/ruff-action@v1
37
+ with:
38
+ args: "format --check"
39
+
40
+ - name: Static type checking (MyPy)
41
+ run: uv run mypy src/clinspector/
42
+
43
+ - name: Run tests
44
+ run: uv run pytest --cov-report=xml --cov=src/clinspector/ --cov-report=term-missing
45
+
46
+ - name: Upload test results to Codecov
47
+ uses: codecov/codecov-action@v4
48
+ with:
49
+ token: ${{ secrets.CODECOV_TOKEN }}
50
+ fail_ci_if_error: false
51
+ verbose: true
52
+
53
+ release:
54
+ runs-on: ubuntu-latest
55
+ needs: test
56
+ if: startsWith(github.ref, 'refs/tags/')
57
+ permissions:
58
+ # this permission is mandatory for trusted publishing
59
+ id-token: write
60
+ contents: write
61
+ steps:
62
+ - name: Check out repository
63
+ uses: actions/checkout@v4
64
+
65
+ - name: Set up Python
66
+ uses: actions/setup-python@v5
67
+ with:
68
+ python-version: "3.12"
69
+
70
+ - name: Install uv
71
+ uses: astral-sh/setup-uv@v3
72
+ with:
73
+ enable-cache: true
74
+ cache-dependency-glob: pyproject.toml
75
+ cache-suffix: py${{ matrix.python_version }}
76
+
77
+ - name: Build package
78
+ run: uv build
79
+
80
+ - name: Release package on PyPI
81
+ run: uv publish
82
+
83
+ - name: Release package on GitHub
84
+ uses: ncipollo/release-action@v1
85
+ with:
86
+ body: ${{ github.event.head_commit.message }}
87
+ artifacts: dist/*.whl,dist/*.tar.gz
88
+ token: ${{ secrets.GITHUB_TOKEN }}
@@ -0,0 +1,57 @@
1
+ name: Build documentation
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+
8
+ # Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
9
+ permissions:
10
+ contents: read
11
+ pages: write
12
+ id-token: write
13
+
14
+ # Allow one concurrent deployment
15
+ concurrency:
16
+ group: "pages"
17
+ cancel-in-progress: true
18
+
19
+ # Default to bash
20
+ defaults:
21
+ run:
22
+ shell: bash
23
+
24
+ jobs:
25
+ build:
26
+ runs-on: ubuntu-latest
27
+
28
+ steps:
29
+ - uses: actions/checkout@v4
30
+ with:
31
+ fetch-depth: 0
32
+ - name: Set up Python
33
+ uses: actions/setup-python@v5
34
+ with:
35
+ python-version: "3.12"
36
+ - name: Install uv
37
+ uses: astral-sh/setup-uv@v3
38
+ - name: Install dependencies
39
+ run: |
40
+ uv sync --all-extras
41
+ - name: Build
42
+ run: uv run mknodes build
43
+ - name: Upload artifact
44
+ uses: actions/upload-pages-artifact@v3
45
+ with:
46
+ path: ./site
47
+
48
+ deploy:
49
+ environment:
50
+ name: github-pages
51
+ url: ${{ steps.deployment.outputs.page_url }}
52
+ runs-on: ubuntu-latest
53
+ needs: build
54
+ steps:
55
+ - name: Deploy to GitHub Pages
56
+ id: deployment
57
+ uses: actions/deploy-pages@v4
@@ -0,0 +1,30 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ # Distribution / packaging
5
+ *.sublime-workspace
6
+ # Unit test / coverage reports
7
+ .coverage
8
+ coverage.xml
9
+ .cache
10
+ .hatch
11
+ .pytest_cache/
12
+ junit.xml
13
+ # Jupyter Notebook
14
+ .ipynb_checkpoints
15
+ # pyenv
16
+ .python-version
17
+ # dotenv
18
+ .env
19
+ # virtualenv
20
+ .venv
21
+ # mkdocs documentation
22
+ /site
23
+ # mypy
24
+ .mypy_cache/
25
+ # .vscode
26
+ .vscode/
27
+ # OS files
28
+ .DS_Store
29
+ # uv
30
+ uv.lock
@@ -0,0 +1,48 @@
1
+ default_language_version:
2
+ python: python3.12
3
+ default_stages: [pre-commit]
4
+ repos:
5
+ - repo: local
6
+ hooks:
7
+ - id: pytest-check
8
+ name: pytest-check
9
+ entry: uv run pytest
10
+ language: system
11
+ # stages: [push]
12
+ types: [python]
13
+ pass_filenames: false
14
+ always_run: true
15
+
16
+ - repo: https://github.com/pre-commit/pre-commit-hooks
17
+ # https://pre-commit.com/hooks.html
18
+ rev: v5.0.0
19
+ hooks:
20
+ - id: check-added-large-files
21
+ - id: check-case-conflict
22
+ - id: check-merge-conflict
23
+ - id: check-toml
24
+ - id: check-json
25
+ - id: check-xml
26
+ - id: check-yaml
27
+ args: [--allow-multiple-documents, --unsafe]
28
+ - id: debug-statements
29
+ - id: detect-private-key
30
+
31
+ - repo: https://github.com/pre-commit/mirrors-mypy
32
+ rev: v1.13.0
33
+ hooks:
34
+ - id: mypy
35
+ additional_dependencies: [orjson]
36
+
37
+ - repo: https://github.com/charliermarsh/ruff-pre-commit
38
+ rev: v0.7.2
39
+ hooks:
40
+ - id: ruff
41
+ - id: ruff-format
42
+
43
+ - repo: https://github.com/commitizen-tools/commitizen
44
+ rev: v3.30.0
45
+ hooks:
46
+ - id: commitizen
47
+ stages: [commit-msg]
48
+ additional_dependencies: [typing-extensions]
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024, Philipp Temminghoff
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
@@ -0,0 +1,179 @@
1
+ Metadata-Version: 2.3
2
+ Name: clinspector
3
+ Version: 0.1.0
4
+ Summary: A library to parse CLI output into structured data.
5
+ Project-URL: Documentation, https://phil65.github.io/clinspector/
6
+ Project-URL: Source, https://github.com/phil65/clinspector
7
+ Author-email: Philipp Temminghoff <philipptemminghoff@googlemail.com>
8
+ License: MIT License
9
+
10
+ Copyright (c) 2024, Philipp Temminghoff
11
+
12
+ Permission is hereby granted, free of charge, to any person obtaining a copy
13
+ of this software and associated documentation files (the "Software"), to deal
14
+ in the Software without restriction, including without limitation the rights
15
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16
+ copies of the Software, and to permit persons to whom the Software is
17
+ furnished to do so, subject to the following conditions:
18
+
19
+ The above copyright notice and this permission notice shall be included in all
20
+ copies or substantial portions of the Software.
21
+
22
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28
+ SOFTWARE.
29
+
30
+ Classifier: Development Status :: 4 - Beta
31
+ Classifier: Intended Audience :: Developers
32
+ Classifier: Operating System :: OS Independent
33
+ Classifier: Programming Language :: Python :: 3
34
+ Classifier: Programming Language :: Python :: 3 :: Only
35
+ Classifier: Programming Language :: Python :: 3.12
36
+ Classifier: Programming Language :: Python :: 3.13
37
+ Classifier: Programming Language :: Python :: 3.14
38
+ Classifier: Topic :: Documentation
39
+ Classifier: Topic :: Software Development
40
+ Classifier: Topic :: Utilities
41
+ Classifier: Typing :: Typed
42
+ Requires-Python: >=3.12
43
+ Requires-Dist: pyparsing
44
+ Provides-Extra: all
45
+ Requires-Dist: cappa; extra == 'all'
46
+ Requires-Dist: cleo; extra == 'all'
47
+ Requires-Dist: click; extra == 'all'
48
+ Requires-Dist: typer; extra == 'all'
49
+ Provides-Extra: cappa
50
+ Requires-Dist: cappa; extra == 'cappa'
51
+ Provides-Extra: cleo
52
+ Requires-Dist: cleo; extra == 'cleo'
53
+ Provides-Extra: click
54
+ Requires-Dist: click; extra == 'click'
55
+ Provides-Extra: typer
56
+ Requires-Dist: typer; extra == 'typer'
57
+ Description-Content-Type: text/markdown
58
+
59
+ # CLInspector
60
+
61
+ [![PyPI License](https://img.shields.io/pypi/l/clinspector.svg)](https://pypi.org/project/clinspector/)
62
+ [![Package status](https://img.shields.io/pypi/status/clinspector.svg)](https://pypi.org/project/clinspector/)
63
+ [![Daily downloads](https://img.shields.io/pypi/dd/clinspector.svg)](https://pypi.org/project/clinspector/)
64
+ [![Weekly downloads](https://img.shields.io/pypi/dw/clinspector.svg)](https://pypi.org/project/clinspector/)
65
+ [![Monthly downloads](https://img.shields.io/pypi/dm/clinspector.svg)](https://pypi.org/project/clinspector/)
66
+ [![Distribution format](https://img.shields.io/pypi/format/clinspector.svg)](https://pypi.org/project/clinspector/)
67
+ [![Wheel availability](https://img.shields.io/pypi/wheel/clinspector.svg)](https://pypi.org/project/clinspector/)
68
+ [![Python version](https://img.shields.io/pypi/pyversions/clinspector.svg)](https://pypi.org/project/clinspector/)
69
+ [![Implementation](https://img.shields.io/pypi/implementation/clinspector.svg)](https://pypi.org/project/clinspector/)
70
+ [![Releases](https://img.shields.io/github/downloads/phil65/clinspector/total.svg)](https://github.com/phil65/clinspector/releases)
71
+ [![Github Contributors](https://img.shields.io/github/contributors/phil65/clinspector)](https://github.com/phil65/clinspector/graphs/contributors)
72
+ [![Github Discussions](https://img.shields.io/github/discussions/phil65/clinspector)](https://github.com/phil65/clinspector/discussions)
73
+ [![Github Forks](https://img.shields.io/github/forks/phil65/clinspector)](https://github.com/phil65/clinspector/forks)
74
+ [![Github Issues](https://img.shields.io/github/issues/phil65/clinspector)](https://github.com/phil65/clinspector/issues)
75
+ [![Github Issues](https://img.shields.io/github/issues-pr/phil65/clinspector)](https://github.com/phil65/clinspector/pulls)
76
+ [![Github Watchers](https://img.shields.io/github/watchers/phil65/clinspector)](https://github.com/phil65/clinspector/watchers)
77
+ [![Github Stars](https://img.shields.io/github/stars/phil65/clinspector)](https://github.com/phil65/clinspector/stars)
78
+ [![Github Repository size](https://img.shields.io/github/repo-size/phil65/clinspector)](https://github.com/phil65/clinspector)
79
+ [![Github last commit](https://img.shields.io/github/last-commit/phil65/clinspector)](https://github.com/phil65/clinspector/commits)
80
+ [![Github release date](https://img.shields.io/github/release-date/phil65/clinspector)](https://github.com/phil65/clinspector/releases)
81
+ [![Github language count](https://img.shields.io/github/languages/count/phil65/clinspector)](https://github.com/phil65/clinspector)
82
+ [![Github commits this week](https://img.shields.io/github/commit-activity/w/phil65/clinspector)](https://github.com/phil65/clinspector)
83
+ [![Github commits this month](https://img.shields.io/github/commit-activity/m/phil65/clinspector)](https://github.com/phil65/clinspector)
84
+ [![Github commits this year](https://img.shields.io/github/commit-activity/y/phil65/clinspector)](https://github.com/phil65/clinspector)
85
+ [![Package status](https://codecov.io/gh/phil65/clinspector/branch/main/graph/badge.svg)](https://codecov.io/gh/phil65/clinspector/)
86
+ [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
87
+ [![PyUp](https://pyup.io/repos/github/phil65/clinspector/shield.svg)](https://pyup.io/repos/github/phil65/clinspector/)
88
+
89
+ [Read the documentation!](https://phil65.github.io/clinspector/)
90
+
91
+ # CLInspector Documentation
92
+
93
+ CLInspector is a library to introspect Python CLI applications and extract their command structure and parameters programmatically.
94
+
95
+ ## Usage
96
+
97
+ The main entry point is the `get_cmd_info()` function which analyzes a CLI application instance and returns a structured `CommandInfo` object:
98
+
99
+ ```python
100
+ from clinspector import get_cmd_info
101
+
102
+ command_info = get_cmd_info(cli_instance)
103
+ ```
104
+
105
+ The function accepts CLI application instances from the following frameworks:
106
+
107
+ - [Typer](https://typer.tiangolo.com/) - `typer.Typer` instances
108
+ - [Click](https://click.palletsprojects.com/) - `click.Group` instances
109
+ - [Cleo](https://cleo.readthedocs.io/) - `cleo.Application` instances
110
+ - [Cappa](https://github.com/DynamicArray/Cappa) - Classes decorated with `@cappa.command`
111
+ - [argparse](https://docs.python.org/3/library/argparse.html) - `ArgumentParser` instances
112
+
113
+ The extracted information is returned as a `CommandInfo` object containing:
114
+
115
+ ### CommandInfo Fields
116
+
117
+ - `name: str` - Name of the command
118
+ - `description: str` - Description/help text
119
+ - `usage: str` - Formatted usage string
120
+ - `subcommands: dict[str, CommandInfo]` - Nested subcommands
121
+ - `deprecated: bool` - Whether command is marked as deprecated
122
+ - `epilog: str | None` - Optional epilog text
123
+ - `hidden: bool` - Whether command is hidden
124
+ - `params: list[Param]` - List of command parameters
125
+
126
+ ### Param Fields
127
+
128
+ - `name: str` - Parameter name
129
+ - `help: str | None` - Help text
130
+ - `default: Any` - Default value
131
+ - `opts: list[str]` - Parameter options (e.g. `["-f", "--flag"]`)
132
+ - `required: bool` - Whether parameter is required
133
+ - `is_flag: bool` - Whether parameter is a flag
134
+ - `multiple: bool` - Whether parameter accepts multiple values
135
+ - `nargs: int | str | None` - Number of arguments accepted
136
+ - `envvar: str | None` - Environment variable name
137
+ - `hidden: bool` - Whether parameter is hidden
138
+ - `param_type_name: Literal["option", "parameter", "argument"]` - Parameter type
139
+ - `type: dict[str, str] | None` - Parameter type information
140
+ - `metavar: str | None` - Display name in help text
141
+
142
+ You can access subcommands using dictionary syntax:
143
+
144
+ ```python
145
+ # Get info for "build" subcommand
146
+ build_info = command_info["build"]
147
+
148
+ # Access nested subcommand
149
+ nested_info = command_info["group"]["subcommand"]
150
+ ```
151
+ ```
152
+
153
+ The extracted information allows you to:
154
+
155
+ - Generate documentation automatically
156
+ - Build command completion
157
+ - Create wrappers and adapters
158
+ - Perform static analysis of CLI interfaces
159
+ - And more!
160
+
161
+ Example output for a click command:
162
+
163
+ ```python
164
+ CommandInfo(
165
+ name="cli",
166
+ description="Example CLI tool",
167
+ usage="cli [OPTIONS] COMMAND [ARGS]...",
168
+ params=[
169
+ Param(name="verbose", help="Enable verbose output", opts=["-v", "--verbose"])
170
+ ],
171
+ subcommands={
172
+ "build": CommandInfo(
173
+ name="build",
174
+ description="Build the project",
175
+ params=[...]
176
+ )
177
+ }
178
+ )
179
+ ```
@@ -0,0 +1,121 @@
1
+ # CLInspector
2
+
3
+ [![PyPI License](https://img.shields.io/pypi/l/clinspector.svg)](https://pypi.org/project/clinspector/)
4
+ [![Package status](https://img.shields.io/pypi/status/clinspector.svg)](https://pypi.org/project/clinspector/)
5
+ [![Daily downloads](https://img.shields.io/pypi/dd/clinspector.svg)](https://pypi.org/project/clinspector/)
6
+ [![Weekly downloads](https://img.shields.io/pypi/dw/clinspector.svg)](https://pypi.org/project/clinspector/)
7
+ [![Monthly downloads](https://img.shields.io/pypi/dm/clinspector.svg)](https://pypi.org/project/clinspector/)
8
+ [![Distribution format](https://img.shields.io/pypi/format/clinspector.svg)](https://pypi.org/project/clinspector/)
9
+ [![Wheel availability](https://img.shields.io/pypi/wheel/clinspector.svg)](https://pypi.org/project/clinspector/)
10
+ [![Python version](https://img.shields.io/pypi/pyversions/clinspector.svg)](https://pypi.org/project/clinspector/)
11
+ [![Implementation](https://img.shields.io/pypi/implementation/clinspector.svg)](https://pypi.org/project/clinspector/)
12
+ [![Releases](https://img.shields.io/github/downloads/phil65/clinspector/total.svg)](https://github.com/phil65/clinspector/releases)
13
+ [![Github Contributors](https://img.shields.io/github/contributors/phil65/clinspector)](https://github.com/phil65/clinspector/graphs/contributors)
14
+ [![Github Discussions](https://img.shields.io/github/discussions/phil65/clinspector)](https://github.com/phil65/clinspector/discussions)
15
+ [![Github Forks](https://img.shields.io/github/forks/phil65/clinspector)](https://github.com/phil65/clinspector/forks)
16
+ [![Github Issues](https://img.shields.io/github/issues/phil65/clinspector)](https://github.com/phil65/clinspector/issues)
17
+ [![Github Issues](https://img.shields.io/github/issues-pr/phil65/clinspector)](https://github.com/phil65/clinspector/pulls)
18
+ [![Github Watchers](https://img.shields.io/github/watchers/phil65/clinspector)](https://github.com/phil65/clinspector/watchers)
19
+ [![Github Stars](https://img.shields.io/github/stars/phil65/clinspector)](https://github.com/phil65/clinspector/stars)
20
+ [![Github Repository size](https://img.shields.io/github/repo-size/phil65/clinspector)](https://github.com/phil65/clinspector)
21
+ [![Github last commit](https://img.shields.io/github/last-commit/phil65/clinspector)](https://github.com/phil65/clinspector/commits)
22
+ [![Github release date](https://img.shields.io/github/release-date/phil65/clinspector)](https://github.com/phil65/clinspector/releases)
23
+ [![Github language count](https://img.shields.io/github/languages/count/phil65/clinspector)](https://github.com/phil65/clinspector)
24
+ [![Github commits this week](https://img.shields.io/github/commit-activity/w/phil65/clinspector)](https://github.com/phil65/clinspector)
25
+ [![Github commits this month](https://img.shields.io/github/commit-activity/m/phil65/clinspector)](https://github.com/phil65/clinspector)
26
+ [![Github commits this year](https://img.shields.io/github/commit-activity/y/phil65/clinspector)](https://github.com/phil65/clinspector)
27
+ [![Package status](https://codecov.io/gh/phil65/clinspector/branch/main/graph/badge.svg)](https://codecov.io/gh/phil65/clinspector/)
28
+ [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
29
+ [![PyUp](https://pyup.io/repos/github/phil65/clinspector/shield.svg)](https://pyup.io/repos/github/phil65/clinspector/)
30
+
31
+ [Read the documentation!](https://phil65.github.io/clinspector/)
32
+
33
+ # CLInspector Documentation
34
+
35
+ CLInspector is a library to introspect Python CLI applications and extract their command structure and parameters programmatically.
36
+
37
+ ## Usage
38
+
39
+ The main entry point is the `get_cmd_info()` function which analyzes a CLI application instance and returns a structured `CommandInfo` object:
40
+
41
+ ```python
42
+ from clinspector import get_cmd_info
43
+
44
+ command_info = get_cmd_info(cli_instance)
45
+ ```
46
+
47
+ The function accepts CLI application instances from the following frameworks:
48
+
49
+ - [Typer](https://typer.tiangolo.com/) - `typer.Typer` instances
50
+ - [Click](https://click.palletsprojects.com/) - `click.Group` instances
51
+ - [Cleo](https://cleo.readthedocs.io/) - `cleo.Application` instances
52
+ - [Cappa](https://github.com/DynamicArray/Cappa) - Classes decorated with `@cappa.command`
53
+ - [argparse](https://docs.python.org/3/library/argparse.html) - `ArgumentParser` instances
54
+
55
+ The extracted information is returned as a `CommandInfo` object containing:
56
+
57
+ ### CommandInfo Fields
58
+
59
+ - `name: str` - Name of the command
60
+ - `description: str` - Description/help text
61
+ - `usage: str` - Formatted usage string
62
+ - `subcommands: dict[str, CommandInfo]` - Nested subcommands
63
+ - `deprecated: bool` - Whether command is marked as deprecated
64
+ - `epilog: str | None` - Optional epilog text
65
+ - `hidden: bool` - Whether command is hidden
66
+ - `params: list[Param]` - List of command parameters
67
+
68
+ ### Param Fields
69
+
70
+ - `name: str` - Parameter name
71
+ - `help: str | None` - Help text
72
+ - `default: Any` - Default value
73
+ - `opts: list[str]` - Parameter options (e.g. `["-f", "--flag"]`)
74
+ - `required: bool` - Whether parameter is required
75
+ - `is_flag: bool` - Whether parameter is a flag
76
+ - `multiple: bool` - Whether parameter accepts multiple values
77
+ - `nargs: int | str | None` - Number of arguments accepted
78
+ - `envvar: str | None` - Environment variable name
79
+ - `hidden: bool` - Whether parameter is hidden
80
+ - `param_type_name: Literal["option", "parameter", "argument"]` - Parameter type
81
+ - `type: dict[str, str] | None` - Parameter type information
82
+ - `metavar: str | None` - Display name in help text
83
+
84
+ You can access subcommands using dictionary syntax:
85
+
86
+ ```python
87
+ # Get info for "build" subcommand
88
+ build_info = command_info["build"]
89
+
90
+ # Access nested subcommand
91
+ nested_info = command_info["group"]["subcommand"]
92
+ ```
93
+ ```
94
+
95
+ The extracted information allows you to:
96
+
97
+ - Generate documentation automatically
98
+ - Build command completion
99
+ - Create wrappers and adapters
100
+ - Perform static analysis of CLI interfaces
101
+ - And more!
102
+
103
+ Example output for a click command:
104
+
105
+ ```python
106
+ CommandInfo(
107
+ name="cli",
108
+ description="Example CLI tool",
109
+ usage="cli [OPTIONS] COMMAND [ARGS]...",
110
+ params=[
111
+ Param(name="verbose", help="Enable verbose output", opts=["-v", "--verbose"])
112
+ ],
113
+ subcommands={
114
+ "build": CommandInfo(
115
+ name="build",
116
+ description="Build the project",
117
+ params=[...]
118
+ )
119
+ }
120
+ )
121
+ ```
File without changes
@@ -0,0 +1,60 @@
1
+ from __future__ import annotations
2
+
3
+ from duty import duty
4
+
5
+
6
+ @duty(capture=False)
7
+ def build(ctx, *args: str):
8
+ """Build a MkNodes page."""
9
+ args_str = " " + " ".join(args) if args else ""
10
+ ctx.run(f"uv run mknodes build{args_str}")
11
+
12
+
13
+ @duty(capture=False)
14
+ def serve(ctx, *args: str):
15
+ """Serve a MkNodes page."""
16
+ args_str = " " + " ".join(args) if args else ""
17
+ ctx.run(f"uv run mknodes serve{args_str}")
18
+
19
+
20
+ @duty(capture=False)
21
+ def test(ctx, *args: str):
22
+ """Serve a MkNodes page."""
23
+ args_str = " " + " ".join(args) if args else ""
24
+ ctx.run(f"uv run pytest{args_str}")
25
+
26
+
27
+ @duty(capture=False)
28
+ def clean(ctx):
29
+ """Clean all files from the Git directory except checked-in files."""
30
+ ctx.run("git clean -dfX")
31
+
32
+
33
+ @duty(capture=False)
34
+ def update(ctx):
35
+ """Update all environment packages using pip directly."""
36
+ ctx.run("uv lock --upgrade")
37
+ ctx.run("uv sync --all-extras")
38
+
39
+
40
+ @duty(capture=False)
41
+ def lint(ctx):
42
+ """Lint the code and fix issues if possible."""
43
+ ctx.run("uv run ruff check --fix --unsafe-fixes .")
44
+ ctx.run("uv run ruff format .")
45
+ ctx.run("uv run mypy src/clinspector/")
46
+
47
+
48
+ @duty(capture=False)
49
+ def lint_check(ctx):
50
+ """Lint the code."""
51
+ ctx.run("uv run ruff check .")
52
+ ctx.run("uv run ruff format --check .")
53
+ ctx.run("uv run mypy src/clinspector/")
54
+
55
+
56
+ @duty(capture=False)
57
+ def version(ctx, *args: str):
58
+ """Bump package version."""
59
+ args_str = " " + " ".join(args) if args else ""
60
+ ctx.run(f"hatch version{args_str}")