Convert Wasp CLI argument handling to optparse-applicative#4240
Draft
cprecioso wants to merge 6 commits into
Draft
Convert Wasp CLI argument handling to optparse-applicative#4240cprecioso wants to merge 6 commits into
cprecioso wants to merge 6 commits into
Conversation
Replace the hand-written `case args of` dispatcher and ad-hoc per-command parsing with a single optparse-applicative parser tree (`Wasp.Cli.Parser`). Command dispatch, validation, and `--help` now derive from one source of truth; the manual usage strings in `Main.hs` are gone. Each command takes a typed args record instead of `[String]`, and `Command.Call.Call` is reduced to what telemetry needs. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@wasp.sh/wasp-cli
@wasp.sh/wasp-cli-darwin-arm64-unknown
@wasp.sh/wasp-cli-darwin-x64-unknown
@wasp.sh/wasp-cli-linux-x64-glibc
@wasp.sh/wasp-cli-linux-x64-musl
commit: |
Invert the CLI parsing so each command module exports a `parserInfo :: ParserInfo (IO ())` mapping its arguments directly to the action to execute (runCommand/runWaspLS wrapped with telemetry). This drops the central Action ADT and actionToCall: Wasp.Cli.Parser is now just a registry of command names, and Main only parses, runs the node check, sets env vars, and executes the returned action. Telemetry moves into each command via Telemetry.runWithTelemetry, so a command reports its own Call (e.g. deploy passes its args, build reports Build) instead of Main mapping it back. printVersion moves to a new Wasp.Cli.Command.Version module. Drop the now-unused async (exe) and optparse-applicative/waspc (test) build-depends. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Each command's parserInfo repeated the same shape: wrap in Opt.info with a progDesc, pick the runCommand runner, and report telemetry, plus the same Opt/Call/Telemetry/runCommand imports. Introduce Wasp.Cli.Command.Definition with combinators (command, commandWithArgs, commandGroup, commandWithSubcommands, leaf/leafWithArgs, runWaspCommand/runWaspCommandAs/ runWaspIO, subcommandsParser) so each command becomes a declarative one-liner and the boilerplate imports disappear. Deploy stays a custom Opt.info (forwardOptions + arg-aware telemetry) and Telemetry.parserInfo stays manual (Definition imports Telemetry, so using it there would cycle). The registry is now a [(name, parserInfo)] list fed to subcommandsParser. Behaviour (dispatch, telemetry, help text) is unchanged. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The build-start "no env vars" error embeds the parser's help text. That rendering helper was inlined in BuildStart.Config; move it to a common util (Wasp.Cli.Util.Parser.renderParserHelp) alongside the other Wasp.Cli.Util.* argument helpers. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
NewAiArgs, StartDbArgs, and WaspLSArgs existed only to ferry parsed values into a single handler that immediately destructured them. Generalize the Definition combinators (commandWithArgs takes Opt.Parser (Command b), leafWithArgs takes Opt.Parser (IO ())) so a handler can be applied directly to its argument parsers, then drop those three records and their named parsers: runNewAi/start now take curried args, and waspls folds its thin runWaspLS wrapper into parserInfo. NewProjectArgs and BuildStartArgs stay (consumed as records in ProjectDescription/Config), as does the TestArgs dispatch ADT. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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
Replaces the hand-written
case args ofdispatcher and the inconsistent per-command argument parsing (someoptparse-applicative, some manual string matching) with a singleoptparse-applicativeparser tree in the newWasp.Cli.Parsermodule, so command dispatch, validation, and--helpall derive from one source of truth. Each command handler now takes a typed args record instead of[String], the obsoleteWasp.Cli.Util.Parserhelper is removed, andCommand.Call.Callis reduced to just what telemetry needs. The hand-maintained usage strings inMain.hsare gone (help is now auto-generated), while the top-level help footer keeps the EXAMPLES section and color-coded community links. No change to user-facing CLI behavior; auto-generated help text formatting differs slightly.Type of change
Checklist
I tested my change in a Wasp app to verify that it works as intended.
🧪 Tests and apps:
examples/kitchen-sink/e2e-tests.waspc/data/Cli/templates, as needed.examples/, as needed.examples/tutorials) I updated the tutorial in the docs (and vice versa).📜 Documentation:
web/docs/.🆕 Changelog: (if change is more than just code/docs improvement)
waspc/ChangeLog.mdwith a user-friendly description of the change.web/docs/migration-guides/.versioninwaspc/waspc.cabalto reflect the changes I introduced.🤖 Generated with Claude Code