Skip to content

Add optparse-applicative command option parsing - #12438

Draft
philderbeast wants to merge 15 commits into
haskell:masterfrom
cabalism:add/optparse-applicative-minimal
Draft

philderbeast wants to merge 15 commits into
haskell:masterfrom
cabalism:add/optparse-applicative-minimal

Conversation

@philderbeast

@philderbeast philderbeast commented Oct 10, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #5607 from the parsing side, the v2 commands (bare, new- and v2- spellings), now parse their command lines with optparse-applicative. Does not include printing the help that I'll take from #12213 separately.

QA Notes

  • cabal build --help and cabal build --list-options should print exactly what they printed before.
  • Any command line that worked before should still work and mean the same thing, including abbreviations such as cabal build --dry and cabal install --lib, where an exact name beats a longer one it is a prefix of.
  • cabal build -j and cabal build --allow-newer on their own should take their defaults and not swallow the next word, so cabal build -j all builds the target all with the default job count.
  • cabal build --lib should be rejected as ambiguous, listing the candidate options.
  • cabal ./script.hs and cabal run ./script.hs -- args should behave as before.
  • cabal build --bogus, an example of a mistyped option now dumps optparse's full usage (I'm not sure I should fix this now, leave it as-is or bundle a fix for it when printing the help with optparse-applicative):
$ cabal-3.18.1.0 build --bogus
Error: cabal-3.18.1.0: unrecognized 'build' option `--bogus'

$ cabal run -v0 cabal-install:exe:cabal -- build --bogus
Error: cabal: Invalid option `--bogus'

Usage: cabal build [(-v|--verbose n) | (--builddir|--distdir|--distpref DIR) |
--keep-temp-files | (-g|--ghc) | --ghcjs | --uhc |
(-w|--with-compiler PATH) | --with-hc-pkg PATH |
--prefix DIR | --bindir DIR | --libdir DIR |
--libsubdir DIR | --dynlibdir DIR | --bytecodelibdir DIR |
--libexecdir DIR | --libexecsubdir DIR | --datadir DIR |
--datasubdir DIR | --docdir DIR | --htmldir DIR |
--haddockdir DIR | --sysconfdir DIR |
--program-prefix PREFIX | --program-suffix SUFFIX |
--enable-library-vanilla | --disable-library-vanilla |
(-p|--enable-library-profiling) |
--disable-library-profiling | --enable-shared |
--disable-shared | --enable-static | --disable-static |
--enable-library-bytecode | --disable-library-bytecode |
--enable-executable-dynamic |
--disable-executable-dynamic | --enable-executable-static |
--disable-executable-static | --enable-profiling |
--disable-profiling | --enable-profiling-shared |
--disable-profiling-shared |
--enable-executable-profiling |
--disable-executable-profiling | --profiling-detail level |
--library-profiling-detail level |
(-O|--enable-optimisation|--enable-optimization n) |
(--disable-optimisation|--disable-optimization) |
--enable-debug-info n | --disable-debug-info |
--enable-build-info | --disable-build-info |
--enable-library-for-ghci | --disable-library-for-ghci |
--enable-split-sections | --disable-split-sections |
--enable-split-objs | --disable-split-objs |
--enable-executable-stripping |
--disable-executable-stripping |
--enable-library-stripping | --disable-library-stripping |
--configure-option OPT | --user | --global |
--package-db DB | (-f|--flags FLAGS) |
--extra-include-dirs PATH | --enable-deterministic |
--disable-deterministic | --ipid IPID | --cid CID |
--extra-lib-dirs PATH | --extra-lib-dirs-static PATH |
--extra-framework-dirs PATH | --extra-prog-path PATH |
--instantiate-with NAME=MOD | --enable-tests |
--disable-tests | --enable-coverage | --disable-coverage |
--enable-library-coverage | --disable-library-coverage |
--enable-benchmarks | --disable-benchmarks |
--enable-relocatable | --disable-relocatable |
--disable-response-files |
--allow-depending-on-private-libs | --coverage-for UNITID |
--ignore-build-tools | --with-alex PATH | --with-ar PATH |
--with-c2hs PATH | --with-cpphs PATH |
--with-doctest PATH | --with-gcc PATH | --with-ghc PATH |
--with-ghc-pkg PATH | --with-ghcjs PATH |
--with-ghcjs-pkg PATH | --with-haddock PATH |
--with-happy PATH | --with-hpc PATH | --with-hsc2hs PATH |
--with-hscolour PATH | --with-jhc PATH | --with-ld PATH |
--with-pkg-config PATH | --with-runghc PATH |
--with-strip PATH | --with-tar PATH | --with-uhc PATH |
--alex-option OPT | --ar-option OPT | --c2hs-option OPT |
--cpphs-option OPT | --doctest-option OPT |
--gcc-option OPT | --ghc-option OPT |
--ghc-pkg-option OPT | --ghcjs-option OPT |
--ghcjs-pkg-option OPT | --haddock-option OPT |
--happy-option OPT | --hpc-option OPT |
--hsc2hs-option OPT | --hscolour-option OPT |
--jhc-option OPT | --ld-option OPT |
--pkg-config-option OPT | --runghc-option OPT |
--strip-option OPT | --tar-option OPT | --uhc-option OPT |
--alex-options OPTS | --ar-options OPTS |
--c2hs-options OPTS | --cpphs-options OPTS |
--doctest-options OPTS | --gcc-options OPTS |
--ghc-options OPTS | --ghc-pkg-options OPTS |
--ghcjs-options OPTS | --ghcjs-pkg-options OPTS |
--haddock-options OPTS | --happy-options OPTS |
--hpc-options OPTS | --hsc2hs-options OPTS |
--hscolour-options OPTS | --jhc-options OPTS |
--ld-options OPTS | --pkg-config-options OPTS |
--runghc-options OPTS | --strip-options OPTS |
--tar-options OPTS | --uhc-options OPTS |
--cabal-lib-version VERSION | --enable-append |
--disable-append | --enable-backup | --disable-backup |
(-c|--constraint CONSTRAINT) | --preference CONSTRAINT |
--solver SOLVER | --allow-older DEPS | --allow-newer DEPS |
--write-ghc-environment-files always|never|ghc8.4.4+ |
--enable-documentation | --disable-documentation |
--doc-index-file TEMPLATE | --dry-run | --only-download |
--max-backjumps NUM | --reorder-goals |
--no-reorder-goals | --count-conflicts |
--no-count-conflicts | --fine-grained-conflicts |
--no-fine-grained-conflicts | --minimize-conflict-set |
--no-minimize-conflict-set | --independent-goals |
--no-independent-goals | --prefer-oldest |
--no-prefer-oldest |
--prefer-version oldest|latest|installed-or-latest |
--shadow-installed-packages |
--no-shadow-installed-packages | --strong-flags |
--no-strong-flags | --allow-boot-library-installs |
--no-allow-boot-library-installs |
--reject-unconstrained-dependencies none|all |
--reinstall | --no-reinstall | --avoid-reinstalls |
--no-avoid-reinstalls | --force-reinstalls |
--no-force-reinstalls | --upgrade-dependencies |
--no-upgrade-dependencies | --only-dependencies |
--no-only-dependencies | --dependencies-only |
--no-dependencies-only | --index-state STATE |
--root-cmd COMMAND | --build-summary TEMPLATE |
--build-log TEMPLATE | --remote-build-reporting LEVEL |
--report-planning-failure | --enable-per-component |
--disable-per-component | --run-tests | --semaphore |
--no-semaphore | (-j|--jobs NUM) | --keep-going |
--offline | --no-offline | --build-timings |
--no-build-timings | --only | --haddock-hoogle |
--haddock-html | --haddock-html-location URL |
--haddock-for-hackage | --haddock-executables |
--haddock-tests | --haddock-benchmarks | --haddock-all |
--haddock-internal | --haddock-css PATH |
(--haddock-hyperlink-source|--haddock-hyperlink-sources|--haddock-hyperlinked-source)
|
--haddock-quickjump | --haddock-hscolour-css PATH |
--haddock-contents-location URL | --haddock-base-url URL |
--haddock-resources-dir DIR | --haddock-output-dir DIR |
--haddock-use-unicode | --test-log TEMPLATE |
--test-machine-log TEMPLATE | --test-show-details FILTER |
--test-keep-tix-files | --test-wrapper FILE |
--test-fail-when-no-test-suites |
--test-options TEMPLATES | --test-option TEMPLATE |
--benchmark-options TEMPLATES |
--benchmark-option TEMPLATE | --project-dir DIR |
--project-file FILE | --project-file-parser PARSER |
--only-configure | --no-only-configure | --list-options |
TARGET]

Compile targets within the project.

@philderbeast
philderbeast marked this pull request as draft October 10, 2026 13:27
@philderbeast
philderbeast force-pushed the add/optparse-applicative-minimal branch 3 times, most recently from ce94093 to f19c915 Compare October 10, 2026 13:52
@philderbeast
philderbeast force-pushed the add/optparse-applicative-minimal branch from f19c915 to cfa9bd8 Compare October 12, 2026 12:55
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.

Modernize command-line parsing with optparse-applicative

1 participant