gdritter repos charter / 53dd780
Actually check for a valid license field Getty Ritter 3 years ago
2 changed file(s) with 38 addition(s) and 15 deletion(s). Collapse all Expand all
6161 where header = "Usage: charter (quick|executable|library) [name]"
6262
6363
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)
6666 where
6767 go (AddBinary n) proj =
68 proj & C.binDetails %~ (C.mkBinary n :)
68 return $ proj & C.binDetails %~ (C.mkBinary n :)
6969 go (AddMod m) proj =
70 proj & C.libDetails %~ fmap (& C.libMods %~ (m :))
70 return $ proj & C.libDetails %~ fmap (& C.libMods %~ (m :))
7171 go (SetCategory s) proj =
72 proj & C.projectDetails . C.projectCategory .~ Just s
72 return $ proj & C.projectDetails . C.projectCategory .~ Just s
7373 go (SetSynopsis s) proj =
74 proj & C.projectDetails . C.projectSynopsis .~ Just s
74 return $ proj & C.projectDetails . C.projectSynopsis .~ Just s
7575 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
8087
8188 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 :))
8491 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 ++))
8794
8895 setupProject :: String -> String -> IO C.Project
8996 setupProject typ name = do
100107 case Opt.getOpt Opt.Permute options args of
101108 (os, [typ, name], []) -> do
102109 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
104113 (_, _, errs) -> do
105114 mapM_ putStrLn errs
106115 Sys.die usageInfo
66 , projectBin
77 , quickBin
88 , library
9
10 , validLicenses
911
1012 , mkBinary
1113 , projectDefaults
139141 _ <- Proc.withCreateProcess pr (\_ _ _ -> Proc.waitForProcess)
140142 write [".gitignore"] defaultGitignore
141143 return ()
144
145
146 validLicenses :: [T.Text]
147 validLicenses =
148 [ "GPL", "AGPL", "LGPL",
149 "BSD2", "BSD3", "BSD4",
150 "MIT", "ISC", "MPL",
151 "Apache", "PublicDomain",
152 "AllRightsReserved",
153 "UnspecifiedLicense",
154 "OtherLicense"
155 ]