Skip to content

Conversation

@elegios
Copy link
Contributor

@elegios elegios commented Mar 27, 2025

This PR introduces a new library for parsing command line flags that's a bit more flexible in how flags are specified, and importantly the ability to specify mutually exclusive flags.

The key idea of the interface is to have a central type OptParser a that represents a set of options that can be parsed from a commandline to produce a value of type a. This type is a functor (via optMap), an applicative (via optPure and optApply), and supports alternatives (via optOr), leading to a very composable interface. It's mildly more annoying to use in MCore than in Haskell because we don't have infix operators or ApplicativeDo, but hopefully the composability wins are worth it anyway.

The library is inspired by https://hackage.haskell.org/package/optparse-applicative and has a similar interface. Currently missing major things (that I think would be nice to have) relative to that library:

  • The ability to specify repeatable flags (e.g., -v in some programs, or --debug-phase in mi).
  • Subcommands (e.g., eval and compile for mi).
  • Automatic generation of auto-complete interfaces.

Things we can do that are pretty neat:

  • Build a nested value representing options without repeatedly traversing the same structure or handling partially constructed values.
  • Mutually exclusive (or optional) sets of flags.
  • Auto-generated --help text and flag.

@elegios elegios force-pushed the optparse-applicative branch from faf894b to 834aaa3 Compare March 28, 2025 11:03
@elegios elegios force-pushed the optparse-applicative branch from 834aaa3 to f82808f Compare March 28, 2025 11:11
@david-broman david-broman merged commit 5b6d13c into miking-lang:develop Mar 30, 2025
1 of 2 checks passed
@elegios elegios deleted the optparse-applicative branch April 16, 2025 09:00
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.

2 participants