0 | module Pack.CmdLn.Opts
2 | import Data.SortedMap
3 | import Pack.CmdLn.Types
6 | import Pack.Config.Types
7 | import System.GetOpts
16 | AdjConf = CurDir -> MetaConfig -> Either PackErr MetaConfig
19 | debug _ = Right . {logLevel := Debug}
22 | quiet _ = Right . {logLevel := Silence}
24 | loglevel : String -> AdjConf
25 | loglevel str _ c = map (\ll => {logLevel := ll} c) (readLogLevel str)
28 | withSrc _ = Right . {withSrc := True}
31 | withDocs _ = Right . {withDocs := True}
34 | useKatla _ = Right . {useKatla := True}
36 | setDB : String -> AdjConf
37 | setDB s _ c = map (\db => {collection := db} c) $
readDBName s
39 | setOutput : String -> AdjConf
40 | setOutput s _ c = map (\o => {output := o} c) $
readBody s
42 | setQuery : QueryType -> AdjConf
43 | setQuery s _ = Right . {queryType := s}
45 | setPrompt : Bool -> AdjConf
46 | setPrompt b _ = Right . {safetyPrompt := b}
48 | setGCPrompt : Bool -> AdjConf
49 | setGCPrompt b _ = Right . {gcPrompt := b}
51 | setGCPurge : Bool -> AdjConf
52 | setGCPurge b _ = Right . {gcPurge := b}
54 | setWarnDepends : Bool -> AdjConf
55 | setWarnDepends b _ = Right . {warnDepends := b}
57 | setSkipTests : Bool -> AdjConf
58 | setSkipTests b _ = Right . {skipTests := b}
60 | setScheme : String -> AdjConf
61 | setScheme s _ = Right . {scheme := fromString s}
63 | setBootstrap : Bool -> AdjConf
64 | setBootstrap b _ = Right . {bootstrap := b}
66 | setBootstrapStage3 : Bool -> AdjConf
67 | setBootstrapStage3 b _ = Right . {bootstrapStage3 := b}
69 | setRlwrap : Maybe String -> AdjConf
70 | setRlwrap args _ = Right . {rlwrap := UseRlwrap $
maybe [] (\s => [NoEscape s]) args}
72 | addExtraArgs : String -> AdjConf
73 | addExtraArgs args _ = Right . {extraArgs $= (++ [NoEscape args])}
75 | setIpkg : String -> AdjConf
76 | setIpkg v (CD dir) c = case readAbsFile dir v of
77 | Right af => Right $
{withIpkg := Use af} c
78 | Left err => Left err
80 | setPkgs : String -> AdjConf
82 | let ps = map MkPkgName . forget $
split (',' ==) str
83 | in Right $
{autoLoad := ForcePkgs ps} c
86 | noIpkg _ = Right . {withIpkg := None}
88 | codegen : String -> AdjConf
89 | codegen v _ = Right . {codegen := fromString v}
91 | setGitInit : AdjConf
92 | setGitInit _ = Right . {gitInit := True}
95 | descs : List $
OptDescr AdjConf
97 | [ MkOpt ['p'] ["package-set"] (ReqArg setDB "<db>")
98 | "Set the curated package set to use."
99 | , MkOpt [] ["cg"] (ReqArg codegen "<codgen>")
101 | Sets the backend to use when building Idris executables
102 | or running the REPL. The default is to use the `chez`
105 | , MkOpt [] ["scheme"] (ReqArg setScheme "<exec>")
107 | Sets the scheme executable for installing the Idris2 compiler.
108 | As a default, this is set to `scheme`.
110 | , MkOpt ['P'] ["packages"] (ReqArg setPkgs "<packages>")
112 | Load the given (comma-separated) list of packages into the REPL
115 | , MkOpt ['s'] ["short-desc"] (NoArg $
setQuery ShortDesc)
117 | Print the short description stored in an `.ipkg` file for
120 | , MkOpt ['l'] ["long-desc"] (NoArg $
setQuery Details)
121 | "Print a detailed description of a package known to pack"
122 | , MkOpt [] ["tree"] (NoArg $
setQuery Tree)
123 | "Print a dependency tree of a package known to pack"
124 | , MkOpt [] ["reverse-tree"] (NoArg $
setQuery ReverseTree)
126 | Print a tree of packages depending on a package know to pack.
127 | Use this to find all packages transitively depending on a specific
130 | , MkOpt ['d'] ["dependencies"] (NoArg $
setQuery Dependencies)
131 | "Print the dependencies of each query result."
132 | , MkOpt ['o'] ["output"] (ReqArg setOutput "<file>")
134 | Name of the output file when compiling or running single Idris source files
135 | This defaults to `_tmppack` if not specified explicitly"
137 | , MkOpt [] ["ipkg"] (NoArg $
setQuery Ipkg)
138 | "Print the full `.ipkg` file of each query result."
139 | , MkOpt [] ["prompt"] (NoArg $
setPrompt True)
141 | Prompt before installing a potentially unsafe package
142 | with custom build hooks.
144 | , MkOpt [] ["no-prompt"] (NoArg $
setPrompt False)
146 | Don't prompt before installing a potentially unsafe package
147 | with custom build hooks.
149 | , MkOpt [] ["gc-prompt"] (NoArg $
setGCPrompt True)
151 | Prompt before deleting directories when running command `gc`.
153 | , MkOpt [] ["gc-purge"] (NoArg $
setGCPurge True)
155 | Remove *all* outdated libraries during garbage collection.
157 | , MkOpt [] ["no-gc-prompt"] (NoArg $
setGCPrompt False)
159 | Don't prompt before deleting directories when running command `gc`.
161 | , MkOpt [] ["no-gc-purge"] (NoArg $
setGCPurge False)
163 | Only remove libraries built with an outdated compiler but not
164 | outdated libraries built with the current compiler during garbage
167 | , MkOpt [] ["bootstrap"] (NoArg $
setBootstrap True)
169 | Use the bootstrap compiler for building Idris2. This takes longer
170 | than without bootstrapping, but it will even work if no Idris2
171 | compiler or an outdated one is on the `$PATH`.
173 | , MkOpt [] ["no-bootstrap"] (NoArg $
setBootstrap False)
175 | Use an existing version of Idris2 when building the compiler.
176 | This will fail if `idris2` is not on the computer's `$PATH` or
177 | is too old to build the current version of the compiler.
179 | , MkOpt [] ["bootstrap-stage3"] (NoArg $
setBootstrapStage3 True)
181 | When bootstrapping, rebuilds the compiler once more using the newly
182 | built compiler to produce a more optimised final version.
184 | , MkOpt [] ["no-bootstrap-stage3"] (NoArg $
setBootstrapStage3 False)
186 | Don't perform an additional compiler rebuild during bootstrapping.
188 | , MkOpt [] ["warn-depends"] (NoArg $
setWarnDepends True)
190 | Issue a warning in precense of a local `depends` directory, which might
191 | interfere with the libraries managed by pack.
193 | , MkOpt [] ["no-warn-depends"] (NoArg $
setWarnDepends False)
195 | Don't issue a warning in precense of a local `depends` directory.
197 | , MkOpt [] ["skip-tests"] (NoArg $
setSkipTests True)
199 | Don't run library tests during collection checking.
200 | This currently only affects the pack-admin utility.
202 | , MkOpt [] ["with-src"] (NoArg withSrc)
204 | Include the source code of a library when installing
205 | it. This allows some editor plugins to jump to the
206 | definitions of functions and data types in other
209 | , MkOpt [] ["with-docs"] (NoArg withDocs)
211 | Include the API documentation when installing libraries.
213 | , MkOpt [] ["use-katla"] (NoArg useKatla)
215 | Use katla to add links to the semantically highlighted API sources.
217 | , MkOpt [] ["with-ipkg"] (ReqArg setIpkg "<.ipkg>")
219 | Use settings and packages from the given `.ipkg` file when
220 | starting a REPL session.
222 | , MkOpt [] ["no-ipkg"] (NoArg noIpkg)
224 | Don't look for an `.ipkg` file in scope when starting a REPL session.
226 | , MkOpt [] ["rlwrap"] (OptArg setRlwrap "<rlwrap args>")
227 | "Run a REPL session in `rlwrap`."
228 | , MkOpt [] ["extra-args"] (ReqArg addExtraArgs "<idris2 args>")
229 | "Any extra arguments to pass to Idris2."
230 | , MkOpt ['v'] ["verbose"] (NoArg debug)
231 | "Print debugging information"
232 | , MkOpt ['q'] ["quiet"] (NoArg quiet)
234 | , MkOpt [] ["log-level"] (ReqArg loglevel "<log level>")
236 | Specify the logging level to use. Accepted values are:
237 | \{joinBy ", " $ show . fst <$> logLevels}.
239 | , MkOpt [] ["git-init"] (NoArg setGitInit)
241 | Initialize git for a pack project.
249 | optionNames : List String
250 | optionNames = foldMap names descs
253 | names : OptDescr a -> List String
254 | names (MkOpt sns lns _ _) =
255 | map (\c => "-\{String.singleton c}") sns ++ map ("--" ++) lns
260 | record ParsedArgs (0 c : Type) {auto 0 prf : Command c} where
261 | constructor MkParsedArgs
263 | cmd : CommandWithArgs c
264 | opts : List AdjConf
269 | getArgs' : HasIO io => io (List String)
270 | getArgs' = drop 1 <$> getArgs
278 | -> {auto _ : Command c}
279 | -> (curDir : CurDir)
280 | -> (args : List String)
281 | -> Either PackErr (ParsedArgs c)
282 | parseOpts c dir args =
283 | case getOpt RequireOrder descs args of
284 | MkResult opts n [] [] => do
285 | cmd <- readCommand c dir n
286 | pure $
MkParsedArgs dir cmd opts
287 | MkResult _ _ (u :: _) _ => Left (UnknownArg u)
288 | MkResult _ _ _ (e :: _) => Left (ErroneousArg e)
308 | -> {auto _ : Command c}
309 | -> (init : MetaConfig)
310 | -> (args : ParsedArgs c)
311 | -> Either PackErr MetaConfig
312 | applyArgs c init args = do
313 | let lvl_m := lookup (cmdName $
fst args.cmd) init.levels
314 | dflt := defaultLevel $
fst args.cmd
316 | init' = {logLevel := fromMaybe dflt lvl_m} init
317 | foldlM (\c,f => f args.curDir c) init' args.opts
328 | \{usageInfo "" descs}
330 | Run `pack help <cmd>` to get detailed information about a command.
332 | Available commands:
333 | \{unlines $ map (indent 2 . fst) Types.namesAndCommands}