FIX: CLI bug fixes and minor updates#1559
Open
jsong468 wants to merge 10 commits intomicrosoft:mainfrom
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves the PyRIT CLI/shell UX by expanding list-targets support (initializers + initialization scripts), tightening argument validation for no-arg commands, fixing help lookup for hyphenated commands, and cleaning up unused CLI plumbing.
Changes:
- Add
list-targetsoption parsing inpyrit_shelland enable--initialization-scriptshandling inpyrit_scan. - Reject unexpected args for commands that should not take arguments and normalize hyphenated command names for
help. - Refactor target listing initialization flow (remove unused
initializer_namesparam) and add unit tests covering new behaviors.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
pyrit/cli/pyrit_shell.py |
Adds arg rejection for no-arg commands; adds option parsing + context override for list-targets; fixes help for hyphenated commands. |
pyrit/cli/pyrit_scan.py |
Resolves --initialization-scripts for --list-targets and surfaces missing-script errors. |
pyrit/cli/frontend_core.py |
Removes unused initializer_names param from list_targets_async and supports initialization-scripts-only population. |
pyrit/cli/_cli_args.py |
Introduces parse_list_targets_arguments for shell-mode parsing. |
pyrit/cli/_banner.py |
Updates banner text to reflect list-targets [opts]. |
tests/unit/cli/test_pyrit_shell.py |
Adds coverage for arg rejection, list-targets option flow, and hyphenated help. |
tests/unit/cli/test_pyrit_scan.py |
Adds coverage for --list-targets with initializers and initialization scripts. |
tests/unit/cli/test_frontend_core.py |
Adds coverage for parse_list_targets_arguments and scripts-only target listing initialization. |
rlundeen2
reviewed
Apr 8, 2026
rlundeen2
reviewed
Apr 8, 2026
rlundeen2
approved these changes
Apr 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR makes minor updates to improve the CLI experience, including the following:
_cli_args.pyto introduce an_ArgSpecdataclass that is used to describe each CLI flag (e.g. initializers, memory-labels, etc.) and how it should be collected and validated. These_ArgSpecobjects are passed into a generic helper called_parse_shell_argumentswhich parses each of the arguments according to their specifications (i.e., flag string, result key for the dictionary, whether or not it takes multiple values as args, and parser for validating/normalizing the user inputted values). This method is called within each of the specific per-command argument parsing methods according to the list of specs associated with that command. This ensures that each argument owns its own validation (each command does not need to know how to parse the arg) and lets us centralize code that was repeated and is extensible for future commands.list-targetslist_targetslist-scenarios)help commanddid not work properly for hyphenated commands such aslist-targetsorlist-initializersinitializer_namesinlist_targets_asyncpyrit_shell, whendo_runanddo_list_targets(with args) create a per-commandFrontendCore, they didn't propagate the shell's startup config (config_file, database, env_files). The new context fell back to the default ~/.pyrit/.pyrit_conf, silently losing any custom config passed via --config-file. This caused per-command contexts to use the wrong database type, env files, operator/operation labels, etc. The fix implemented here is to use awith_overrides()method inFrontendCoreto create a derived instance without re-loading and reading config files (usingobject.__new()__and not__init__), copy over inherited state (which includes _database, _env_files, _operator, _operation, _config) as the base, applies overrides on the per-command fields (initializer_names,initialization_scripts,log_level), and shares the parent's registries. Bothdo_runanddo_list_targetsnow use this method. Also sets_silent_reinit = Trueon the derived context to suppress redundant initialization output.._configattribute inFrontEndCoresince it is dead state and not referenced anywhere beyond being set.Tests and Documentation
Unit tests added to ensure behavior of all of the above changes