1
1
mirror of https://github.com/anoma/juvix.git synced 2024-12-15 18:13:56 +03:00
juvix/app/GlobalOptions.hs
Jonathan Cubides 3b0cde27bb
Add CLI improvements and shell testing (#131)
* 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
2022-06-09 16:36:07 +02:00

80 lines
2.2 KiB
Haskell

module GlobalOptions
( module GlobalOptions,
)
where
import Commands.Extra
import MiniJuvix.Prelude
import Options.Applicative hiding (hidden)
data GlobalOptions = GlobalOptions
{ _globalNoColors :: Bool,
_globalShowNameIds :: Bool,
_globalOnlyErrors :: Bool,
_globalNoTermination :: Bool,
_globalInputFiles :: [FilePath]
}
deriving stock (Eq, Show)
makeLenses ''GlobalOptions
defaultGlobalOptions :: GlobalOptions
defaultGlobalOptions =
GlobalOptions
{ _globalNoColors = False,
_globalShowNameIds = False,
_globalOnlyErrors = False,
_globalNoTermination = False,
_globalInputFiles = []
}
instance Semigroup GlobalOptions where
o1 <> o2 =
GlobalOptions
{ _globalNoColors = o1 ^. globalNoColors || o2 ^. globalNoColors,
_globalShowNameIds = o1 ^. globalShowNameIds || o2 ^. globalShowNameIds,
_globalOnlyErrors = o1 ^. globalOnlyErrors || o2 ^. globalOnlyErrors,
_globalNoTermination = o1 ^. globalNoTermination || o2 ^. globalNoTermination,
_globalInputFiles = o1 ^. globalInputFiles ++ o2 ^. globalInputFiles
}
instance Monoid GlobalOptions where
mempty = defaultGlobalOptions
mappend = (<>)
-- | Get a parser for global flags which can be hidden or not depending on
-- the input boolean
parseGlobalFlags :: Bool -> Parser GlobalOptions
parseGlobalFlags b = do
_globalNoColors <-
switch
( long "no-colors"
<> help "Disable ANSI formatting"
<> hidden b
)
_globalShowNameIds <-
switch
( long "show-name-ids"
<> help "Show the unique number of each identifier when pretty printing"
<> hidden b
)
_globalOnlyErrors <-
switch
( long "only-errors"
<> help "Only print errors in a uniform format (used by minijuvix-mode)"
<> hidden b
)
_globalNoTermination <-
switch
( long "no-termination"
<> help "Disable termination checking"
<> hidden b
)
return GlobalOptions {_globalInputFiles = [], ..}
parseGlobalOptions :: Bool -> Parser GlobalOptions
parseGlobalOptions b = do
opts <- parseGlobalFlags b
files <- parserInputFiles
return opts {_globalInputFiles = files}