Skip to content

Commit c87cdcf

Browse files
committed
Add a README to the files generated by cabal init
See #11231
1 parent 8365cec commit c87cdcf

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

cabal-install/src/Distribution/Client/Init/Defaults.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ module Distribution.Client.Init.Defaults
2323
, defaultLicenseIds
2424
, defaultMainIs
2525
, defaultChangelog
26+
, defaultReadme
2627
, defaultCategories
2728
, defaultInitFlags
2829
, defaultLanguage
@@ -75,6 +76,9 @@ defaultPackageType = Executable
7576
defaultChangelog :: FilePath
7677
defaultChangelog = "CHANGELOG.md"
7778

79+
defaultReadme :: FilePath
80+
defaultReadme = "README.md"
81+
7882
defaultLicense :: CabalSpecVersion -> SpecLicense
7983
defaultLicense csv
8084
| csv < CabalSpecV2_2 = SpecLicense $ Right AllRightsReserved

cabal-install/src/Distribution/Client/Init/FileCreators.hs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ module Distribution.Client.Init.FileCreators
1818
( -- * Commands
1919
writeProject
2020
, writeLicense
21+
, writeReadme
2122
, writeChangeLog
2223
, prepareLibTarget
2324
, prepareExeTarget
@@ -70,6 +71,7 @@ writeProject (ProjectSettings opts pkgDesc libTarget exeTarget testTarget)
7071

7172
writeLicense opts pkgDesc
7273
writeChangeLog opts pkgDesc
74+
writeReadme opts pkgDesc
7375

7476
let pkgFields = mkPkgDescription opts pkgDesc
7577
commonStanza = mkCommonStanza opts
@@ -240,6 +242,28 @@ writeChangeLog opts pkgDesc
240242
go =
241243
void $ writeFileSafe opts defaultChangelog changeLog
242244

245+
writeReadme :: Interactive m => WriteOpts -> PkgDescription -> m ()
246+
writeReadme opts pkgDesc
247+
| Just docs <- _pkgExtraDocFiles pkgDesc
248+
, defaultReadme `Set.member` docs =
249+
go
250+
| defaultReadme `elem` _pkgExtraSrcFiles pkgDesc = go
251+
| otherwise = return ()
252+
where
253+
readme =
254+
unlines
255+
[ "# " ++ prettyShow (_pkgName pkgDesc)
256+
, ""
257+
, "## Build"
258+
, ""
259+
, "Run `$ cabal build` to build the project"
260+
, "## Documentation"
261+
, ""
262+
, "Run `$ cabal haddock --open` to generate a reference for the API of the project."
263+
]
264+
go =
265+
void $ writeFileSafe opts defaultReadme readme
266+
243267
-- -------------------------------------------------------------------- --
244268
-- Utilities
245269

cabal-install/tests/UnitTests/Distribution/Client/Init/Simple.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ simplePkgDesc pkgName =
168168
""
169169
""
170170
mempty
171-
(Just $ Set.singleton defaultChangelog)
171+
(Just $ Set.fromList [defaultReadme, defaultChangelog])
172172

173173
simpleLibTarget :: [Dependency] -> LibTarget
174174
simpleLibTarget baseDep =

0 commit comments

Comments
 (0)