Add -help-json flag for machine-readable CLI help#7198
Open
ewels wants to merge 3 commits into
Open
Conversation
✅ Deploy Preview for nextflow-docs-staging ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Adds a global `-help-json` flag to the Nextflow CLI that prints the current command's help, usage and options as JSON, plus an index of all available commands at the root level. This lets tools and LLMs discover the CLI without scraping the rendered `-help` text. A new `CliSchema` class introspects the JCommander `@Parameter` / `@Parameters` annotations to build the schema. A tip pointing at the flag is added to the main usage screen. Signed-off-by: Phil Ewels <phil.ewels@seqera.io> Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Signed-off-by: Phil Ewels <phil.ewels@seqera.io>
Signed-off-by: Phil Ewels <phil.ewels@seqera.io> Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Signed-off-by: Phil Ewels <phil.ewels@seqera.io>
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.
Why
Coding agents and tooling increasingly drive the Nextflow CLI, but the only machine interface to it today is the rendered
-helptext. Scraping that output is brittle: it's formatted for humans, wraps to the terminal width, and changes layout without notice. An LLM (or any tool) wanting to know "what flags doesnextflow runtake, and what type is each one?" has to parse prose.This adds a structured, stable contract for that question. It's a direct port of the idea in nf-core/tools#4310, which added
--help-jsonto the nf-core CLI for the same reason — so agents can discover the CLI reliably one command at a time, rather than pulling the whole tree into context or guessing from help text.The design follows the same principles as the nf-core PR:
nextflow -help-jsonreturns the global options plus an index of every command; drilling into a command (nextflow run -help-json) returns that command's full option/argument detail. Agents navigate down rather than loading everything at once.CliSchemaclass reads the JCommander@Parameter/@Parametersannotations directly — the same source of truth that drives-help— so the JSON can't drift from the real CLI.-helpscreen points tools and agents at the flag.The flag is marked as a
help-style option, so it works even when required arguments are missing (just like-help).What it looks like
nextflow -help-json— global options + a name/description index of every command:{ "name": "nextflow", "path": "nextflow", "usage": "nextflow [options] COMMAND [arg...]", "params": [ ... 11 global options ... ], "subcommands": { "run": { "help": "Execute a pipeline project" }, "config": { "help": "Print a project configuration" }, "lineage":{ "help": "Explore workflows lineage metadata", "aliases": ["li"] }, "...": {} } }nextflow info -help-json— a single command's full detail:{ "name": "info", "path": "nextflow info", "usage": "nextflow info [options] [args...]", "params": [ { "name": "args", "kind": "argument", "type": "List", "help": "project name" }, { "name": "detailed", "kind": "option", "type": "boolean", "opts": ["-d"], "help": "Show detailed information", "is_flag": true }, { "name": "format", "kind": "option", "type": "String", "opts": ["-o"], "help": "Output format, either: text (default), json, yaml" }, { "name": "checkForUpdates", "kind": "option", "type": "boolean", "opts": ["-u", "-check-updates"], "help": "Check for remote updates", "is_flag": true } ], "help": "Print project and system runtime information" }Notes
-h,-help,-help-json) are excluded from the reported parameters, matching what-helpshows.lineage,plugin) report their own options; their sub-commands aren't yet indexed — a reasonable follow-up.CliSchemaTestcover the root schema, a command schema, and alias surfacing. ExistingLauncherTesttests still pass.🤖 Generated with Claude Code