easy --no-switch complement to --switch
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 35/100
Direzione di ricerca
The issue names no repository files or tests; start by locating the existing Parser, flag', long, many, and Mod FlagFields definitions in optparse-applicative. Compare their current behavior with the proposed invertableSwitch and invertableSwitch' entry points. Done means the library offers a documented --foo/--no-foo complement with the stated default and last-occurrence behavior, supported by tests.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
A fairly common idiom in option parsing libraries is for --no-switch to be available as a way to disable an earlier --switch on the command line.
This is useful eg, when you have a shell alias foo = foo --switch, so foo --no-switch can be used to override . Another use case is to help future-proof a program; if it later changes so --switch is enabled by default, then users of both the old and the new version can use --no-switch to get the old behavior.
This is a bit clumsy to do with optparse-applicative, unless I'm missing an easy way to do it. Here's an implementation that makes it easy. I'd be happy if this or something like it were added to your library.
-- | A switch that can be enabled using --foo and disabled using --no-foo.
--
-- The option modifier is applied to only the option that is *not* enabled
-- by default. For example:
--
-- > invertableSwitch "recursive" True (help "do not recurse into directories")
--
-- This example makes --recursive enabled by default, so
-- the help is shown only for --no-recursive.
invertableSwitch
:: String -- ^ long option
-> Bool -- ^ is switch enabled by default?
-> Mod FlagFields Bool -- ^ option modifier
-> Parser Bool
invertableSwitch longopt defv optmod = invertableSwitch' longopt defv
(if defv then mempty else optmod)
(if defv then optmod else mempty)
-- | Allows providing option modifiers for both --foo and --no-foo.
invertableSwitch'
:: String -- ^ long option (eg "foo")
-> Bool -- ^ is switch enabled by default?
-> Mod FlagFields Bool -- ^ option modifier for --foo
-> Mod FlagFields Bool -- ^ option modifier for --no-foo
-> Parser Bool
invertableSwitch' longopt defv enmod dismod = collapse <$> many
( flag' True (enmod <> long longopt)
<|> flag' False (dismod <> long nolongopt)
)
where
nolongopt = "no-" ++ longopt
collapse [] = defv
collapse l = last l
- Lingua principale
- Haskell
- Stelle
- 957
- Fork
- 124
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di pcapriotti/optparse-applicative
-
Allow QuickCheck 2.17Aperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 75/100
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 42/100
pcapriotti/optparse-applicative#524 · 2 commenti ·
-
Allow replacing commands with metavar when using parserOptionGroupForse già presa @tbidne l’ha presa 86 giorni fa. Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
pcapriotti/optparse-applicative#523 · 1 commento · 1 reazione ·
-
Nushell CompletionsAperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
pcapriotti/optparse-applicative#513 · 4 commenti ·
Tutte le issue di pcapriotti/optparse-applicative
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
IntersectMBO/cardano-ledger#6276 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
OpenZeppelin/canton-contracts#92 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
hasura/graphql-engine#10954 ·
I maintainer di solito rispondono entro 1 giorno