forked from purescript/purescript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.hs
More file actions
92 lines (83 loc) · 3.66 KB
/
Main.hs
File metadata and controls
92 lines (83 loc) · 3.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
module Main where
import Prelude
import Command.Bundle qualified as Bundle
import Command.Compile qualified as Compile
import Command.Docs qualified as Docs
import Command.Graph qualified as Graph
import Command.Hierarchy qualified as Hierarchy
import Command.Ide qualified as Ide
import Command.QuickBuild qualified as QB
import Command.Publish qualified as Publish
import Command.REPL qualified as REPL
import Control.Monad (join)
import Data.Foldable (fold)
import Options.Applicative qualified as Opts
import System.Environment (getArgs)
import System.IO qualified as IO
import Text.PrettyPrint.ANSI.Leijen qualified as Doc
import Version (versionString)
main :: IO ()
main = do
IO.hSetEncoding IO.stdout IO.utf8
IO.hSetEncoding IO.stderr IO.utf8
IO.hSetBuffering IO.stdout IO.LineBuffering
IO.hSetBuffering IO.stderr IO.LineBuffering
join $ Opts.handleParseResult . execParserPure opts =<< getArgs
where
opts = Opts.info (versionInfo <*> Opts.helper <*> commands) infoModList
infoModList = Opts.fullDesc <> headerInfo <> footerInfo
headerInfo = Opts.progDesc "The PureScript compiler and tools"
footerInfo = Opts.footerDoc (Just footer)
footer =
mconcat
[ para $
"For help using each individual command, run `purs COMMAND --help`. " ++
"For example, `purs compile --help` displays options specific to the `compile` command."
, Doc.hardline
, Doc.hardline
, Doc.text $ "purs " ++ versionString
]
para :: String -> Doc.Doc
para = foldr (Doc.</>) Doc.empty . map Doc.text . words
-- | Displays full command help when invoked with no arguments.
execParserPure :: Opts.ParserInfo a -> [String] -> Opts.ParserResult a
execParserPure pinfo [] = Opts.Failure $
Opts.parserFailure Opts.defaultPrefs pinfo (Opts.ShowHelpText Nothing) mempty
execParserPure pinfo args = Opts.execParserPure Opts.defaultPrefs pinfo args
versionInfo :: Opts.Parser (a -> a)
versionInfo = Opts.abortOption (Opts.InfoMsg versionString) $
Opts.long "version" <> Opts.help "Show the version number" <> Opts.hidden
commands :: Opts.Parser (IO ())
commands =
(Opts.subparser . fold)
[ Opts.command "bundle"
(Opts.info Bundle.command
(Opts.progDesc "This command was removed in v0.15.0. Run this command for migration information."))
, Opts.command "sqlite"
(Opts.info Bundle.initSqlite
(Opts.progDesc "Init sqlite"))
, Opts.command "compile"
(Opts.info Compile.command
(Opts.progDesc "Compile PureScript source files"))
, Opts.command "docs"
(Opts.info Docs.command
(Opts.progDesc "Generate documentation from PureScript source files in a variety of formats, including Markdown and HTML" <> Docs.infoModList))
, Opts.command "graph"
(Opts.info Graph.command
(Opts.progDesc "Module dependency graph"))
, Opts.command "hierarchy"
(Opts.info Hierarchy.command
(Opts.progDesc "Generate a GraphViz directed graph of PureScript type classes"))
, Opts.command "ide"
(Opts.info Ide.command
(Opts.progDesc "Start or query an IDE server process"))
, Opts.command "qb"
(Opts.info QB.command
(Opts.progDesc "Quick build module"))
, Opts.command "publish"
(Opts.info Publish.command
(Opts.progDesc "Generates documentation packages for upload to Pursuit"))
, Opts.command "repl"
(Opts.info REPL.command
(Opts.progDesc "Enter the interactive mode (PSCi)"))
]