Add --help-json flag for machine-readable CLI help#4310
Draft
ewels wants to merge 6 commits into
Draft
Conversation
Adds a global `--help-json` flag to every command and group, printing the current command's help, usage and full parameter detail as JSON, plus a recursive index of subcommand names. This lets LLMs and tooling discover the CLI one level at a time without parsing rendered `--help` text or pulling the whole command tree into context. A `--help-json` name (rather than `--json`) is used because several commands already define their own `--json` data-output flag. A footer tip is also added to every `--help` screen to advertise the flag. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
awgymer
approved these changes
Jun 1, 2026
awgymer
left a comment
Contributor
There was a problem hiding this comment.
Looks good, but should we add a test for this on the top-level command at least?
Member
Author
|
@claude please add a test for the top-level command |
Contributor
|
Shouldn't this be added upstream in rich-click instead 😉 |
Member
Author
|
Not a bad idea at all! |
This was referenced Jun 2, 2026
Member
Author
|
Added upstream but will leave this PR open so that we don't forget. Will still need to pin updated rich-click and add a config option if it remains opt-in. |
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.
Summary
Adds a global
--help-jsonflag to every nf-core CLI command and group. It prints the current command's full help, usage and parameter detail as JSON, plus a recursive index of subcommand names, so LLMs and tooling can discover the entire CLI one level at a time. (Hat-tip to @awgymer for the idea!)How it works
nf_core/cli_schema.pyintrospects the Click/rich-clickcommand tree (get_paramsthenParam.to_info_dict(),list_commands/get_command,collect_usage_pieces), with no--helptext parsing.JSONGroup/JSONCommandclass pair on the root group. Becauserich-click'sgroup_classis alreadytype, a singlecls=on the root propagates--help-jsonto all commands automatically, with no per-command boilerplate.--helpscreen (viarich_click'sFOOTER_TEXT) so agents landing on the human help are pointed at the JSON flag.Design notes
--help --jsonbut the latter collided, so--help-jsonit isnf-core <any command> --help-jsonworks even when required arguments are missing (like--help).Examples
Regular
--helpnow advertises the flag (footer)The tip is appended to every help screen:
nf-core --help-json: root top-level options plus recursive name index of the whole CLI{ "name": "nf-core-cli", "path": "nf-core", "help": "nf-core/tools provides a set of helper tools for use with nf-core Nextflow pipelines.\n\nIt is designed for both end-users running pipelines and also developers creating new pipelines.", "usage": "nf-core [OPTIONS] COMMAND [ARGS]...", "params": [ { "name": "version", "kind": "option", "opts": ["--version"], "type": "Bool", "is_flag": true, "help": "Show the version and exit." }, { "name": "verbose", "kind": "option", "opts": ["-v", "--verbose"], "type": "Bool", "is_flag": true, "help": "Print verbose output to the console." }, { "name": "hide_progress", "kind": "option", "opts": ["--hide-progress"], "type": "Bool", "is_flag": true, "help": "Don't show progress bars." }, { "name": "log_file", "kind": "option", "opts": ["-l", "--log-file"], "type": "String", "help": "Save a verbose log to a file." } ], "subcommands": { "interface": {}, "modules": { "bump-versions": {}, "create": {}, "info": {}, "install": {}, "lint": {}, "list": { "local": {}, "remote": {} }, "patch": {}, "remove": {}, "test": {}, "update": {} }, "pipelines": { "bump-version": {}, "create": {}, "create-logo": {}, "create-params-file": {}, "download": {}, "launch": {}, "lint": {}, "list": {}, "rocrate": {}, "schema": { "build": {}, "docs": {}, "lint": {}, "validate": {} }, "sync": {} }, "subworkflows": { "create": {}, "info": {}, "install": {}, "lint": {}, "list": { "local": {}, "remote": {} }, "patch": {}, "remove": {}, "test": {}, "update": {} }, "test-datasets": { "list": {}, "list-branches": {}, "search": {} } } }nf-core modules --help-json: a group, its own options, aliases, and immediate subcommand index{ "name": "modules", "path": "nf-core modules", "help": "Commands to manage Nextflow DSL2 modules (tool wrappers).", "usage": "nf-core modules [OPTIONS] COMMAND [ARGS]...", "params": [ { "name": "git_remote", "kind": "option", "opts": ["-g", "--git-remote"], "type": "String", "help": "Remote git repo to fetch files from", "default": "https://github.com/nf-core/modules.git" }, { "name": "branch", "kind": "option", "opts": ["-b", "--branch"], "type": "String", "help": "Branch of git repository hosting modules." }, { "name": "no_pull", "kind": "option", "opts": ["-N", "--no-pull"], "type": "Bool", "is_flag": true, "help": "Do not pull in latest changes to local clone of modules repository." } ], "aliases": ["m", "module"], "subcommands": { "bump-versions": {}, "create": {}, "info": {}, "install": {}, "lint": {}, "list": { "local": {}, "remote": {} }, "patch": {}, "remove": {}, "test": {}, "update": {} } }nf-core pipelines schema validate --help-json: a leaf command, full options plus positional arguments{ "name": "validate", "path": "nf-core pipelines schema validate", "help": "Validate a set of parameters against a pipeline schema.", "usage": "nf-core pipelines schema validate [OPTIONS] <pipeline name> <JSON params file>", "params": [ { "name": "directory", "kind": "option", "opts": ["-d", "--dir"], "type": "Path", "help": "Pipeline directory. [default: current working directory]", "default": "." }, { "name": "pipeline", "kind": "argument", "opts": ["pipeline"], "type": "String" }, { "name": "params", "kind": "argument", "opts": ["params"], "type": "Path", "required": true } ] }Notes
tests/test_cli.pytests pass.UserWarning: The parameter -b is used more than once(a duplicate-bshort flag aroundmodules/bump-version) surfaced while introspecting the tree. This is unrelated to this PR, but worth a follow-up fix.🤖 Generated with Claude Code