mirror of
https://github.com/anoma/juvix.git
synced 2024-12-15 18:13:56 +03:00
3b0cde27bb
* Remove input file fields from command opts * [cli] Make version and help commands * Fix on reviews * Fixes for dealing with global options inside subcmds * Fix minijuvix emacs mode and add some instance to GlobalOpts * Remove unrelated code * Propagate globals opts in each cmd parser * Add initial shell tests * Add test-shell to makefile and CI * Fix CI: adding .local/bin to PATH * Fixing CI * Installing shelltest just before running it * Install app for shell testing * Hide global flags after cmd. Fix shell tests accordingly. * Fixing CI * Shell test only run on ubuntu for now
48 lines
1.4 KiB
Haskell
48 lines
1.4 KiB
Haskell
module Commands.Extra where
|
|
|
|
import MiniJuvix.Prelude hiding (Doc)
|
|
import Options.Applicative
|
|
import Options.Applicative.Builder.Internal
|
|
import Options.Applicative.Types
|
|
|
|
parserInputFile :: Parser FilePath
|
|
parserInputFile =
|
|
argument
|
|
str
|
|
( metavar "MINIJUVIX_FILE"
|
|
<> help "Path to a .mjuvix file"
|
|
<> action "file"
|
|
)
|
|
|
|
parserInputFiles :: Parser [FilePath]
|
|
parserInputFiles = many parserInputFile
|
|
|
|
addParser :: forall a c. Monoid a => Parser a -> Parser c -> Parser (a, c)
|
|
addParser parser = \case
|
|
(NilP p) -> NilP ((\c -> (mempty, c)) <$> p)
|
|
(OptP (Option (CmdReader n cs g) ps)) ->
|
|
OptP (Option (CmdReader n cs (fmap optsInfo . g)) ps)
|
|
where
|
|
optsInfo :: ParserInfo b -> ParserInfo (a, b)
|
|
optsInfo pInfo = pInfo {infoParser = newParser}
|
|
where
|
|
newParser = do
|
|
opts <- parser
|
|
rest <- infoParser pInfo
|
|
pure (opts, rest)
|
|
(OptP o) -> OptP ((mempty,) <$> o)
|
|
(AltP p1 p2) -> AltP (addParser parser p1) (addParser parser p2)
|
|
(MultP p1 p2) ->
|
|
MultP
|
|
((\(g2, f) (g1, x) -> (g1 <> g2, f x)) <$> addParser parser p1)
|
|
(addParser parser p2)
|
|
(BindP p k) -> BindP (addParser parser p) $ \(g1, x) ->
|
|
BindP (addParser parser $ k x) $ \(g2, x') ->
|
|
pure (g1 <> g2, x')
|
|
|
|
hidden :: Bool -> Mod f a
|
|
hidden sure = optionMod $ \p ->
|
|
if
|
|
| not sure -> p
|
|
| otherwise -> p {propVisibility = min Hidden (propVisibility p)}
|