pcapriotti / pcapriotti/optparse-applicative

Options shown in Global section can include unreachable alternatives.

Open
#461 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Haskell
Stars
959
Forks
123
Avg merge
3d 19h
Merged PRs (30d)
1

Description

Hello 👋🏼

The CLI for Unison has one very common use-case (launching the unison shell) and several other 'utility' commands. The way we have things set up right now is as follows:

  • ucm without any subcommand runs the 'launch' behaviour
  • ucm run defers to the run subcommand.

The way we've implemented this is by using our launch option parser as a fallback for our subcommand parser:

topLevelParser =
  hsubparser subcommands <|> launchCommand

Meaning that if the user doesn't provide a command, we interpret it as a 'launch'.

The issue is that currently optparse-applicative interprets all of the options of launch as global options, even though all of those options will fail if passed to the run subcommand for example.

Is there any way to indicate options as being only relevant if no subcommand is provided, rather than showing them as global?

Effectively I want the empty command to just be treated as another subcommand.

This may not be the most common setup, but if you can think of a way to make this work I'd love to hear it 😄

Thank you for maintaining such an awesome tool, it saves us a lot of time :D

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by examining the topLevelParser expression in the issue, especially how hsubparser combines subcommands with launchCommand as a fallback. Read the parser-combinator implementation and existing parser tests to determine whether an empty command can be represented separately from global options. Done means launch options are shown only for the no-subcommand path and are rejected or absent for commands such as run.

Written by the indexing model from the issue text.

Assessment

Tech stack
haskell
Domain
cli
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.