on master help sign in
[ fix #4255 ] Not silently accepting invalid options

squashing various attempts into one commit. Not using the 'output' file as, looking at various pkg00N, this does not seem to be needed. Also moving pkg009 to pkg010 to avoid conflicts with master Finally, stylize wants some imports moved around

commit377d87ab17f8481d608aa3de2554eb899db8ad5f authorGuillaume Allais <guillaume.allais@ens-lyon.org> dateFri 15 Dec 2017, 16:41 (9 years ago) parent5813103
6 files changed+53−5
src/Idris/CmdOptions.hs+7−3 src/Idris/Package/Parser.hs+11−1 test/TestData.hs+2−1 test/pkg010/expected+28 test/pkg010/run+2 test/pkg010/wrongopts.ipkg+3
src/Idris/CmdOptions.hs+7−3
@@ -10,7 +10,8 @@ Maintainer : The Idris Community.
1010
1111module Idris.CmdOptions
1212 ( opt, getClient, getPkg, getPkgCheck, getPkgClean, getPkgMkDoc,
13− getPkgREPL, getPkgTest, getPort, getIBCSubDir, pureArgParser, runArgParser
13+ getPkgREPL, getPkgTest, getPort, getIBCSubDir,
14+ pureArgParser, execArgParserPure, runArgParser
1415 ) where
1516
1617import Idris.Info (getIdrisVersion)
@@ -72,10 +73,13 @@ runArgParser = do opts <- execParser $ info parser
7273 PP.empty,
7374 PP.indent 4 (PP.text "http://www.idris-lang.org/")]
7475
76+execArgParserPure :: [String] -> ParserResult [Opt]
77+execArgParserPure args = preProcOpts <$> execParserPure (prefs idm) (info parser idm) args
78+
7579pureArgParser :: [String] -> [Opt]
76−pureArgParser args = case getParseResult $ execParserPure (prefs idm) (info parser idm) args of
80+pureArgParser args = case getParseResult (execArgParserPure args) of
7781 Just opts -> preProcOpts opts
78− Nothing -> []
82+ Nothing -> []
7983
8084parser :: Parser [Opt]
8185parser = runA $ proc () -> do
src/Idris/Package/Parser.hs+11−1
@@ -10,6 +10,7 @@ module Idris.Package.Parser where
1010
1111import Idris.CmdOptions
1212import Idris.Imports
13+import Idris.Options (Opt)
1314import Idris.Package.Common
1415import Idris.Parser (moduleName)
1516import Idris.Parser.Helpers (Parser, Parsing, eol, iName, identifier, isEol,
@@ -19,6 +20,7 @@ import Idris.Parser.Helpers (Parser, Parsing, eol, iName, identifier, isEol,
1920import Control.Applicative
2021import Control.Monad.State.Strict
2122import Data.List (union)
23+import qualified Options.Applicative as Opts
2224import System.Directory (doesFileExist)
2325import System.Exit
2426import System.FilePath (isValid, takeExtension, takeFileName)
@@ -109,11 +111,19 @@ clause name p f = do value <- reserved name *> lchar '=' *> p <* someSpace
109111commaSep :: Parsing m => m a -> m [a]
110112commaSep p = P.sepBy1 p (lchar ',')
111113
114+pOptions :: PParser [Opt]
115+pOptions = do
116+ str <- stringLiteral
117+ case execArgParserPure (words str) of
118+ Opts.Success a -> return a
119+ Opts.Failure e -> fail $ fst $ Opts.renderFailure e ""
120+ _ -> fail "Unexpected error"
121+
112122pClause :: PParser ()
113123pClause = clause "executable" filename (\st v -> st { execout = Just v })
114124 <|> clause "main" (iName []) (\st v -> st { idris_main = Just v })
115125 <|> clause "sourcedir" identifier (\st v -> st { sourcedir = v })
116− <|> clause "opts" (pureArgParser . words <$> stringLiteral) (\st v -> st { idris_opts = v ++ idris_opts st })
126+ <|> clause "opts" pOptions (\st v -> st { idris_opts = v ++ idris_opts st })
117127 <|> clause "pkgs" (commaSep (pPkgName <* someSpace)) (\st ps ->
118128 let pkgs = pureArgParser $ concatMap (\x -> ["-p", show x]) ps
119129 in st { pkgdeps = ps `union` pkgdeps st
test/TestData.hs+2−1
@@ -205,7 +205,8 @@ testFamiliesData = [
205205 ( 5, ANY ),
206206 ( 6, ANY ),
207207 ( 7, ANY ),
208− ( 8, ANY )]),
208+ ( 8, ANY ),
209+ ( 10, ANY )]),
209210 ("prelude", "Prelude",
210211 [ ( 1, ANY )]),
211212 ("primitives", "Primitive types",
test/pkg010/expectednew file+28
@@ -0,0 +1,28 @@
1+Uncaught error: user error (wrongopts.ipkg:4:1:
2+ |
3+4 | <empty line>
4+ | ^
5+Invalid option `-total'
6+
7+Usage: ([--nobanner] | [-q|--quiet] | [--ide-mode] | [--ide-mode-socket] |
8+ [--client ARG] | [--log LEVEL] | [--logging-categories CATS] |
9+ [--nobasepkgs] | [--noprelude] | [--nobuiltins] | [--check] |
10+ [-o|--output FILE] | [--interface] | [--typeintype] | [--total] |
11+ [--partial] | [--warnpartial] | [--warnreach] | [--warnipkg] |
12+ [--nocoverage] | [--errorcontext] | [--info] | [--listlogcats] |
13+ [--link] | [--listlibs] | [--libdir] | [--docdir] | [--include] | [--V2]
14+ | [--V1] | [-V|--V0|--verbose] | [--ibcsubdir FILE] |
15+ [-i|--idrispath ARG] | [--sourcepath ARG] | [--warn] |
16+ [-p|--package ARG] | [--port PORT] | [--build IPKG] | [--install IPKG] |
17+ [--repl IPKG] | [--clean IPKG] | [--mkdoc IPKG] | [--installdoc IPKG] |
18+ [--checkpkg IPKG] | [--testpkg IPKG] | [--indent-with INDENT] |
19+ [--indent-clause INDENT] | [--bytecode ARG] | [-S|--codegenonly] |
20+ [-c|--compileonly] | [--dumpdefuns ARG] | [--dumpcases ARG] |
21+ [--codegen TARGET] | [--portable-codegen TARGET] | [--cg-opt ARG] |
22+ [-e|--eval EXPR] | [--execute] | [--exec EXPR] | [-X|--extension EXT] |
23+ [--O3] | [--O2] | [--O1] | [--O0] | [--partial-eval] |
24+ [--no-partial-eval] | [-O|--level ARG] | [--target TRIPLE] | [--cpu CPU]
25+ | [--color|--colour] | [--nocolor|--nocolour] | [--consolewidth WIDTH] |
26+ [--highlight] | [--no-elim-deprecation-warnings] |
27+ [--no-tactic-deprecation-warnings]) [FILES] [-v|--version]
28+)
test/pkg010/runnew file+2
@@ -0,0 +1,2 @@
1+#!/usr/bin/env bash
2+${IDRIS:-idris} $@ --build wrongopts.ipkg
test/pkg010/wrongopts.ipkgnew file+3
@@ -0,0 +1,3 @@
1+package wrongopts
2+
3+opts = "-total"