61 | 61 |
where header = "Usage: charter (quick|executable|library) [name]"
|
62 | 62 |
|
63 | 63 |
|
64 | |
process :: [Option] -> C.Project -> C.Project
|
65 | |
process opts p = foldl (flip ($)) p (map go opts)
|
| 64 |
process :: [Option] -> C.Project -> Either String C.Project
|
| 65 |
process opts p = foldl (>>=) (return p) (map go opts)
|
66 | 66 |
where
|
67 | 67 |
go (AddBinary n) proj =
|
68 | |
proj & C.binDetails %~ (C.mkBinary n :)
|
| 68 |
return $ proj & C.binDetails %~ (C.mkBinary n :)
|
69 | 69 |
go (AddMod m) proj =
|
70 | |
proj & C.libDetails %~ fmap (& C.libMods %~ (m :))
|
| 70 |
return $ proj & C.libDetails %~ fmap (& C.libMods %~ (m :))
|
71 | 71 |
go (SetCategory s) proj =
|
72 | |
proj & C.projectDetails . C.projectCategory .~ Just s
|
| 72 |
return $ proj & C.projectDetails . C.projectCategory .~ Just s
|
73 | 73 |
go (SetSynopsis s) proj =
|
74 | |
proj & C.projectDetails . C.projectSynopsis .~ Just s
|
| 74 |
return $ proj & C.projectDetails . C.projectSynopsis .~ Just s
|
75 | 75 |
go (SetDescription s) proj =
|
76 | |
proj & C.projectDetails . C.projectDescription .~ Just s
|
77 | |
go (SetLicense s) proj =
|
78 | |
proj & C.projectDetails . C.projectLicense .~ Just s
|
79 | |
go (SetRoot _) proj = proj
|
| 76 |
return $ proj & C.projectDetails . C.projectDescription .~ Just s
|
| 77 |
go (SetLicense license) proj
|
| 78 |
| not (license `elem` C.validLicenses) =
|
| 79 |
Left $ concat [ "Unknown license: `"
|
| 80 |
, T.unpack license
|
| 81 |
, "'\n\nValid Cabal licenses include:\n - "
|
| 82 |
, T.unpack (T.intercalate "\n - " C.validLicenses)
|
| 83 |
]
|
| 84 |
| otherwise =
|
| 85 |
return $ proj & C.projectDetails . C.projectLicense .~ Just license
|
| 86 |
go (SetRoot _) proj = return proj
|
80 | 87 |
|
81 | 88 |
go (AddDep dep) proj =
|
82 | |
proj & C.binDetails %~ fmap (& C.execDeps %~ (dep :))
|
83 | |
& C.libDetails %~ fmap (& C.libDeps %~ (dep :))
|
| 89 |
return $ proj & C.binDetails %~ fmap (& C.execDeps %~ (dep :))
|
| 90 |
& C.libDetails %~ fmap (& C.libDeps %~ (dep :))
|
84 | 91 |
go (AddUsualDeps) proj =
|
85 | |
proj & C.binDetails %~ fmap (& C.execDeps %~ (C.usualDeps ++))
|
86 | |
& C.libDetails %~ fmap (& C.libDeps %~ (C.usualDeps ++))
|
| 92 |
return $ proj & C.binDetails %~ fmap (& C.execDeps %~ (C.usualDeps ++))
|
| 93 |
& C.libDetails %~ fmap (& C.libDeps %~ (C.usualDeps ++))
|
87 | 94 |
|
88 | 95 |
setupProject :: String -> String -> IO C.Project
|
89 | 96 |
setupProject typ name = do
|
|
100 | 107 |
case Opt.getOpt Opt.Permute options args of
|
101 | 108 |
(os, [typ, name], []) -> do
|
102 | 109 |
proj <- process os <$> setupProject typ name
|
103 | |
C.createProject proj
|
| 110 |
case proj of
|
| 111 |
Right p -> C.createProject p
|
| 112 |
Left err -> Sys.die err
|
104 | 113 |
(_, _, errs) -> do
|
105 | 114 |
mapM_ putStrLn errs
|
106 | 115 |
Sys.die usageInfo
|