This repository was archived by the owner on Aug 26, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMain.hs
More file actions
62 lines (51 loc) · 1.94 KB
/
Main.hs
File metadata and controls
62 lines (51 loc) · 1.94 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
{- |
The Main module.
-}
module Main where
import System.Console.GetOpt
import System.Environment
import System.Exit
import Hellno
import Hellno.Packages
import Hellno.Cabal
import Hellno.Core
data Opt = Opt String | ArgOpt String String
instance Eq Opt where
(==) (Opt s) (Opt s') = s == s'
(==) (ArgOpt s _) (ArgOpt s' _) = s == s'
(==) _ _ = False
simpleOpt :: Char -> String -> String -> OptDescr Opt
simpleOpt c o s = Option [c] [o] (NoArg $ Opt o) s
options = [
simpleOpt 'h' "help" "display this help message"
]
usageHeader = unlines [
"Usage:",
"hellno [OPTIONS] < setup | try | install | depclean > [PACKAGES]",
"hellno [OPTIONS] < reset | local-install >\n",
"Modes:",
"setup - bring in all (and only) dependencies required by package(s)",
"try - the same as setup but don't install anything",
"install - install the package. For local packages, do use local-install.",
"local-install - install using cabal-src-install",
"depclean - clean the database so that only packages required by at least",
"one of the arguments remain",
"reset - reset the environment so that only fixed packages remain\n",
"Options:"
]
handleArgs :: [Opt] -> [String] -> [String] -> IO ()
handleArgs opts mode err
| not (null err) = mapM_ putStrLn err >> exitFailure
| Opt "help" `elem` opts = putStrLn (usageInfo usageHeader options)
| ("setup":xs) <- mode = setupEnvironment False xs
| ("try":xs) <- mode = setupEnvironment True xs
| ("depclean":xs) <- mode = cleanDatabase xs
| ("install":xs) <- mode = cabalInstallPackage xs
| ("local-install":[]) <- mode = cabalSrcInstall
| ("reset":[]) <- mode = clearPackages >> recacheUserDb
| otherwise = putStrLn "Error: No mode specified or unknown mode." >>
exitFailure
main = do
(opts, mode, err) <- fmap (getOpt RequireOrder options) $ instPrefix `seq`
ghcPkg `seq` pkgRoot `seq` getArgs
handleArgs opts mode err