Skip to content

Add unified dissect command entry point - #111

Open
yunzheng wants to merge 5 commits into
mainfrom
add-unified-dissect-cli
Open

yunzheng wants to merge 5 commits into
mainfrom
add-unified-dissect-cli

Conversation

@yunzheng

@yunzheng yunzheng commented Sep 10, 2026 •

Copy link
Copy Markdown
Member

This PR adds a single dissect command that dispatches to the various target-* tools as describe in #104, so they can be run without installing/knowing each script name:

$ uvx dissect shell <target>      ->  target-shell <target>
$ uvx --pre dissect dd <target>   ->  target-dd <target>

$ dissect --help
 usage: dissect [-h] <command> ...

 Unified entry point for the dissect target-* tools.

 positional arguments:
   <command>
     shell             run target-shell
     dd                run target-dd
     ...

DISCLAIMER: Claude made this using my prompts, the pyproject.toml and tox.ini fixups were done manually.

Changes

  • New dissect/cli.py dispatcher exposed via [project.scripts] as dissect = "dissect.cli:main".
  • Subcommands are discovered dynamically from the console_scripts entry points (any target-<name> becomes dissect <name>), so the list stays in sync automatically.
  • Uses argparse with subparsers for a proper --help/command listing and clean error handling, then forwards the remaining args to the underlying tool verbatim (sidestepping the argparse.REMAINDER leading-option bug).
  • Subcommand help uses each tool's module docstring summary, extracted statically via ast (no import, no side effects). Falls back to run target-<name> when a tool has no docstring.
  • pyproject.toml: enabled namespace package discovery (namespaces = true, include = ["dissect", "dissect.*"]) so dissect/cli.py is packaged while keeping dissect a PEP 420 namespace package (no __init__.py).

Notes

Currently we should add a one-line module docstring to the target-* tools in dissect.target, which would make the dissect --help listing more descriptive. They now fall back to a generic string, which is: run target-<name>.

Introduce a `dissect` console script that forwards subcommands to the
installed `target-*` tools, e.g. `dissect shell <target>` runs
`target-shell` and `dissect dd <target>` runs `target-dd`.

Subcommands are discovered dynamically from the `console_scripts` entry
points, so any `target-<name>` tool is automatically available as
`dissect <name>`. Help listings use each tool's module docstring
summary (read statically, without importing the tool), falling back to
`run target-<name>`.
@yunzheng
yunzheng force-pushed the add-unified-dissect-cli branch from a51adf2 to d1b77b6 Compare September 10, 2026 12:58
@yunzheng

yunzheng commented Sep 10, 2026 •

Copy link
Copy Markdown
Member Author

This does not solve:

Because this tool dump-nskeyedarchiver lives in dissect.util. However we could add that I guess? Same applies for possible other tools/entrypoints that can be discovered dynamically.

UPDATE: is now discoverable via --help-all in commit below.

* added benchmarks and tests
* added --help-all
* cli color support for Python 3.14+
@yunzheng

yunzheng commented Sep 11, 2026 •

Copy link
Copy Markdown
Member Author

Added a new commit that adds the following improvements to the unified dissect cli:

  • Added a --help-all option, which lists ALL commands in the dissect.* namespace.
  • --help will only list the target commands.
  • Added fast-path, meaning that the CLI has minimal imports if we directly specify a <command> to run to reduce startup time. Only when --help or --help-all is specified the parser is built using importlib and ast.
  • Added benchmarks to keep track of startup times over time and ensure fast-path keeps fast.

Some screenshots below for comparison and tracking progress over time (click to open):

screenshot of previous `dissect --help` image
screenshot of `dissect --help` image
screenshot of `dissect --help-all` image

@codecov

codecov Bot commented Sep 11, 2026

Copy link
Copy Markdown

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

Thanks for integrating Codecov - We've got you covered ☂️

@codspeed

codspeed Bot commented Sep 11, 2026 •

Copy link
Copy Markdown

Congrats! CodSpeed is installed 🎉

🆕 12 new benchmarks were detected.

You will start to see performance impacts in the reports once the benchmarks are run from your default branch.

Detected benchmarks


Open in CodSpeed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The reviewed changes are covered by tests and CI updates with no unresolved blocking issues.

Pull request overview

Adds a unified dissect CLI that dynamically discovers and dispatches installed target tools.

Changes:

  • Added CLI dispatcher and console entry point.
  • Added dynamic command discovery, help generation, and argument forwarding.
  • Added tests, benchmarking, lint configuration, and CI coverage.
  • Updated namespace package discovery.
File summaries
File Description
tox.ini Adds benchmark, lint, and formatting environments.
tests/test_cli.py Adds functional and benchmark tests.
tests/conftest.py Handles optional benchmark dependencies.
tests/__init__.py Adds the tests package marker.
pyproject.toml Registers the CLI and configures package discovery.
dissect/cli.py Implements command discovery, dispatch, and help generation.
.github/workflows/dissect-ci.yml Enables linting, tests, and benchmarks.
Review details
  • Files reviewed: 6/7 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread dissect/cli.py Outdated
Comment thread dissect/cli.py
@yunzheng
yunzheng requested a review from twiggler September 24, 2026 08:22

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for uvx dissect

3 participants