3Module : Idris.CmdOptions
4Description : A parser for the CmdOptions for the Idris executable.
6Maintainer : The Idris Community.
11module Idris.CmdOptions
12 ( opt, getClient, getPkg, getPkgCheck, getPkgClean, getPkgMkDoc,
13 getPkgREPL, getPkgTest, getPort, getIBCSubDir, pureArgParser, runArgParser
16import Idris.Info (getIdrisVersion)
18import IRTS.CodegenCommon
20import Control.Monad.Trans (lift)
21import Control.Monad.Trans.Except (throwE)
22import Control.Monad.Trans.Reader (ask)
25import Data.Monoid ((<>))
26import Options.Applicative
27import Options.Applicative.Arrows
28import Options.Applicative.Types (ReadM(..))
30import Text.ParserCombinators.ReadP hiding (many, option)
33import qualified Text.PrettyPrint.ANSI.Leijen as PP
35runArgParser :: IO [Opt]
36runArgParser = do opts <- execParser $ info parser
38 <> headerDoc (Just idrisHeader)
39 <> progDescDoc (Just idrisProgDesc)
40 <> footerDoc (Just idrisFooter)
42 return $ preProcOpts opts
44 idrisHeader = PP.hsep [PP.text "Idris version", PP.text getIdrisVersion, PP.text ", (C) The Idris Community 2016"]
45 idrisProgDesc = PP.vsep [PP.empty,
46 PP.text "Idris is a general purpose pure functional programming language with dependent",
47 PP.text "types. Dependent types allow types to be predicated on values, meaning that",
48 PP.text "some aspects of a program's behaviour can be specified precisely in the type.",
49 PP.text "It is compiled, with eager evaluation. Its features are influenced by Haskell",
52 PP.vsep $ map (PP.indent 4 . PP.text) [
53 "+ Full dependent types with dependent pattern matching",
54 "+ Simple case expressions, where-clauses, with-rule",
55 "+ Pattern matching let- and lambda-bindings",
56 "+ Overloading via Interfaces (Type class-like), Monad comprehensions",
57 "+ do-notation, idiom brackets",
58 "+ Syntactic conveniences for lists, tuples, dependent pairs",
59 "+ Totality checking",
60 "+ Coinductive types",
61 "+ Indentation significant syntax, Extensible syntax",
62 "+ Tactic based theorem proving (influenced by Coq)",
63 "+ Cumulative universes",
64 "+ Simple Foreign Function Interface",
65 "+ Hugs style interactive environment"
67 idrisFooter = PP.vsep [PP.text "It is important to note that Idris is first and foremost a research tool",
68 PP.text "and project. Thus the tooling provided and resulting programs created",
69 PP.text "should not necessarily be seen as production ready nor for industrial use.",
71 PP.text "More details over Idris can be found online here:",
73 PP.indent 4 (PP.text "http://www.idris-lang.org/")]
75pureArgParser :: [String] -> [Opt]
76pureArgParser args = case getParseResult $ execParserPure (prefs idm) (info parser idm) args of
77 Just opts -> preProcOpts opts
81parser = runA $ proc () -> do
82 flags <- asA parseFlags -< ()
83 files <- asA (many $ argument (fmap Filename str) (metavar "FILES")) -< ()
84 A parseVersion >>> A helper -< (flags ++ files)
86parseFlags :: Parser [Opt]
88 flag' NoBanner (long "nobanner" <> help "Suppress the banner")
89 <|> flag' Quiet (short 'q' <> long "quiet" <> help "Quiet verbosity")
91 -- IDE Mode Specific Flags
92 <|> flag' Idemode (long "ide-mode" <> help "Run the Idris REPL with machine-readable syntax")
93 <|> flag' IdemodeSocket (long "ide-mode-socket" <> help "Choose a socket for IDE mode to listen on")
96 <|> Client <$> strOption (long "client")
99 <|> OLogging <$> option auto (long "log" <> metavar "LEVEL" <> help "Debugging log level")
100 <|> OLogCats <$> option (str >>= parseLogCats)
101 (long "logging-categories"
103 <> help "Colon separated logging categories. Use --listlogcats to see list.")
106 <|> flag' NoBasePkgs (long "nobasepkgs" <> help "Do not use the given base package")
107 <|> flag' NoPrelude (long "noprelude" <> help "Do not use the given prelude")
108 <|> flag' NoBuiltins (long "nobuiltins" <> help "Do not use the builtin functions")
110 <|> flag' NoREPL (long "check" <> help "Typecheck only, don't start the REPL")
112 <|> Output <$> strOption (short 'o' <> long "output" <> metavar "FILE" <> help "Specify output file")
114 -- <|> flag' TypeCase (long "typecase")
115 <|> flag' Interface (long "interface" <> help "Generate interface files from ExportLists")
116 <|> flag' TypeInType (long "typeintype" <> help "Turn off Universe checking")
117 <|> flag' DefaultTotal (long "total" <> help "Require functions to be total by default")
118 <|> flag' DefaultPartial (long "partial")
119 <|> flag' WarnPartial (long "warnpartial" <> help "Warn about undeclared partial functions")
120 <|> flag' WarnReach (long "warnreach" <> help "Warn about reachable but inaccessible arguments")
121 <|> flag' AuditIPkg (long "warnipkg" <> help "Warn about possible incorrect package specifications")
122 <|> flag' NoCoverage (long "nocoverage")
123 <|> flag' ErrContext (long "errorcontext")
126 <|> flag' ShowAll (long "info" <> help "Display information about installation.")
127 <|> flag' ShowLoggingCats (long "listlogcats" <> help "Display logging categories")
128 <|> flag' ShowLibs (long "link" <> help "Display link flags")
129 <|> flag' ShowPkgs (long "listlibs" <> help "Display installed libraries")
130 <|> flag' ShowLibDir (long "libdir" <> help "Display library directory")
131 <|> flag' ShowDocDir (long "docdir" <> help "Display idrisdoc install directory")
132 <|> flag' ShowIncs (long "include" <> help "Display the includes flags")
134 <|> flag' (Verbose 3) (long "V2" <> help "Loudest verbosity")
135 <|> flag' (Verbose 2) (long "V1" <> help "Louder verbosity")
136 <|> flag' (Verbose 1) (short 'V' <> long "V0" <>long "verbose" <> help "Loud verbosity")
138 <|> IBCSubDir <$> strOption (long "ibcsubdir" <> metavar "FILE" <> help "Write IBC files into sub directory")
139 <|> ImportDir <$> strOption (short 'i' <> long "idrispath" <> help "Add directory to the list of import paths")
140 <|> SourceDir <$> strOption (long "sourcepath" <> help "Add directory to the list of source search paths")
142 <|> flag' WarnOnly (long "warn")
144 <|> Pkg <$> strOption (short 'p' <> long "package" <> help "Add package as a dependency")
145 <|> Port <$> option portReader (long "port" <> metavar "PORT" <> help "REPL TCP port - pass \"none\" to not bind any port")
148 <|> PkgBuild <$> strOption (long "build" <> metavar "IPKG" <> help "Build package")
149 <|> PkgInstall <$> strOption (long "install" <> metavar "IPKG" <> help "Install package")
150 <|> PkgREPL <$> strOption (long "repl" <> metavar "IPKG" <> help "Launch REPL, only for executables")
151 <|> PkgClean <$> strOption (long "clean" <> metavar "IPKG" <> help "Clean package")
152 <|> (PkgDocBuild <$> strOption (long "mkdoc" <> metavar "IPKG" <> help "Generate IdrisDoc for package"))
153 <|> PkgDocInstall <$> strOption (long "installdoc" <> metavar "IPKG" <> help "Install IdrisDoc for package")
154 <|> PkgCheck <$> strOption (long "checkpkg" <> metavar "IPKG" <> help "Check package only")
155 <|> PkgTest <$> strOption (long "testpkg" <> metavar "IPKG" <> help "Run tests for package")
157 -- Interactive Editing Flags
158 <|> IndentWith <$> option auto (long "indent-with"
160 <> help "Indentation to use with :makewith (default 2)")
161 <|> IndentClause <$> option auto (long "indent-clause"
163 <> help "Indentation to use with :addclause (default 2)")
166 <|> BCAsm <$> strOption (long "bytecode")
168 <|> flag' (OutputTy Raw) (short 'S' <> long "codegenonly" <> help "Do no further compilation of code generator output")
169 <|> flag' (OutputTy Object) (short 'c' <> long "compileonly" <> help "Compile to object files rather than an executable")
171 <|> DumpDefun <$> strOption (long "dumpdefuns")
172 <|> DumpCases <$> strOption (long "dumpcases")
174 <|> (UseCodegen . parseCodegen) <$> strOption (long "codegen"
176 <> help "Select code generator: C, Javascript, Node and bytecode are bundled with Idris")
178 <|> ((UseCodegen . Via JSONFormat) <$> strOption (long "portable-codegen"
180 <> help "Pass the name of the code generator. This option is for codegens that take JSON formatted IR."))
182 <|> CodegenArgs <$> strOption (long "cg-opt"
184 <> help "Arguments to pass to code generator")
186 <|> EvalExpr <$> strOption (long "eval"
189 <> help "Evaluate an expression without loading the REPL")
191 <|> flag' (InterpretScript "Main.main") (long "execute" <> help "Execute as idris")
192 <|> InterpretScript <$> strOption (long "exec" <> metavar "EXPR" <> help "Execute as idris")
194 <|> ((Extension . getExt) <$> strOption (long "extension"
197 <> help "Turn on language extension (TypeProviders or ErrorReflection)"))
199 -- Optimisation Levels
200 <|> flag' (OptLevel 3) (long "O3")
201 <|> flag' (OptLevel 2) (long "O2")
202 <|> flag' (OptLevel 1) (long "O1")
203 <|> flag' (OptLevel 0) (long "O0")
205 <|> flag' (AddOpt PETransform) (long "partial-eval")
206 <|> flag' (RemoveOpt PETransform) (long "no-partial-eval" <> help "Switch off partial evaluation, mainly for debugging purposes")
208 <|> OptLevel <$> option auto (short 'O' <> long "level")
210 <|> TargetTriple <$> strOption (long "target" <> metavar "TRIPLE" <> help "If supported the codegen will target the named triple.")
211 <|> TargetCPU <$> strOption (long "cpu" <> metavar "CPU" <> help "If supported the codegen will target the named CPU e.g. corei7 or cortex-m3")
214 <|> flag' (ColourREPL True) (long "colour" <> long "color" <> help "Force coloured output")
215 <|> flag' (ColourREPL False) (long "nocolour" <> long "nocolor" <> help "Disable coloured output")
217 <|> (UseConsoleWidth <$> option (str >>= parseConsoleWidth) (long "consolewidth" <> metavar "WIDTH" <> help "Select console width: auto, infinite, nat"))
219 <|> flag' DumpHighlights (long "highlight" <> help "Emit source code highlighting")
221 <|> flag' NoElimDeprecationWarnings (long "no-elim-deprecation-warnings" <> help "Disable deprecation warnings for %elim")
222 <|> flag' NoOldTacticDeprecationWarnings (long "no-tactic-deprecation-warnings" <> help "Disable deprecation warnings for the old tactic sublanguage")
225 getExt :: String -> LanguageExt
226 getExt s = fromMaybe (error ("Unknown extension " ++ s)) (maybeRead s)
227 maybeRead :: String -> Maybe LanguageExt
228 maybeRead = fmap fst . listToMaybe . reads
229 portReader :: ReadM REPLPort
231 ((ListenPort . fromIntegral) <$> auto) <|>
232 (ReadM $ do opt <- ask
233 if map toLower opt == "none"
234 then return $ DontListen
235 else lift $ throwE $ ErrorMsg $
236 "got " <> opt <> " expected port number or \"none\"")
238parseVersion :: Parser (a -> a)
239parseVersion = infoOption getIdrisVersion (short 'v' <> long "version" <> help "Print version information")
241preProcOpts :: [Opt] -> [Opt]
242preProcOpts (NoBuiltins : xs) = NoBuiltins : NoPrelude : preProcOpts xs
243preProcOpts (Output s : xs) = Output s : NoREPL : preProcOpts xs
244preProcOpts (BCAsm s : xs) = BCAsm s : NoREPL : preProcOpts xs
245preProcOpts (x:xs) = x : preProcOpts xs
248parseCodegen :: String -> Codegen
249parseCodegen "bytecode" = Bytecode
250parseCodegen cg = Via IBCFormat (map toLower cg)
252parseLogCats :: Monad m => String -> m [LogCat]
254 case lastMay (readP_to_S doParse s) of
255 Just (xs, _) -> return xs
256 _ -> fail "Incorrect categories specified"
258 doParse :: ReadP [LogCat]
260 cs <- sepBy1 parseLogCat (char ':')
264 parseLogCat :: ReadP [LogCat]
265 parseLogCat = (string (strLogCat IParse) *> return parserCats)
266 <|> (string (strLogCat IElab) *> return elabCats)
267 <|> (string (strLogCat ICodeGen) *> return codegenCats)
268 <|> (string (strLogCat ICoverage) *> return [ICoverage])
269 <|> (string (strLogCat IIBC) *> return [IIBC])
270 <|> (string (strLogCat IErasure) *> return [IErasure])
273 parseLogCatBad :: ReadP [LogCat]
276 fail $ "Category: " ++ s ++ " is not recognised."
278parseConsoleWidth :: Monad m => String -> m ConsoleWidth
279parseConsoleWidth "auto" = return AutomaticWidth
280parseConsoleWidth "infinite" = return InfinitelyWide
282 case lastMay (readP_to_S integerReader s) of
283 Just (r, _) -> return $ ColsWide r
284 _ -> fail $ "Cannot parse: " ++ s
286integerReader :: ReadP Int
288 digits <- many1 $ satisfy isDigit
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list