Skip to content

Commit 1d10444

Browse files
authored
Merge pull request #8274 from haskell/mergify/bp/3.8/pr-8267
cabal init -i should autodetect author name and maintainer email (backport #8267)
2 parents 0c78856 + 268d66e commit 1d10444

File tree

4 files changed

+37
-8
lines changed

4 files changed

+37
-8
lines changed

cabal-install/src/Distribution/Client/Init/Interactive/Command.hs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ import Distribution.Client.Init.FlagExtractors
5353
import Distribution.Client.Init.Prompt
5454
import Distribution.Client.Init.Types
5555
import Distribution.Client.Init.Utils
56+
import Distribution.Client.Init.NonInteractive.Heuristics (guessAuthorName, guessAuthorEmail)
5657
import Distribution.FieldGrammar.Newtypes (SpecLicense(..))
5758
import Distribution.Simple.Setup (Flag(..), fromFlagOrDefault)
5859
import Distribution.Simple.PackageIndex (InstalledPackageIndex)
@@ -355,12 +356,14 @@ licensePrompt flags = getLicense flags $ do
355356
else fmap prettyShow knownLicenses
356357

357358
authorPrompt :: Interactive m => InitFlags -> m String
358-
authorPrompt flags = getAuthor flags $
359-
promptStr "Author name" OptionalPrompt
359+
authorPrompt flags = getAuthor flags $ do
360+
name <- guessAuthorName
361+
promptStr "Author name" (DefaultPrompt name)
360362

361363
emailPrompt :: Interactive m => InitFlags -> m String
362-
emailPrompt flags = getEmail flags $
363-
promptStr "Maintainer email" OptionalPrompt
364+
emailPrompt flags = getEmail flags $ do
365+
email' <- guessAuthorEmail
366+
promptStr "Maintainer email" (DefaultPrompt email')
364367

365368
homepagePrompt :: Interactive m => InitFlags -> m String
366369
homepagePrompt flags = getHomepage flags $

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,9 @@ pkgArgs = fromList
340340
, "y"
341341
, "0.1.0.0"
342342
, "2"
343+
, "git username"
343344
, "foo-kmett"
345+
, "git email"
344346
345347
, "home"
346348
, "synopsis"

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

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,10 @@ createProjectTest pkgIx srcDb = testGroup "createProject tests"
145145
-- license
146146
, "3"
147147
-- author
148+
, "git username"
148149
, "Foobar"
149150
-- email
151+
, "git email"
150152
151153
-- homepage
152154
, "qux.com"
@@ -249,8 +251,10 @@ createProjectTest pkgIx srcDb = testGroup "createProject tests"
249251
-- license
250252
, "3"
251253
-- author
254+
, "git username"
252255
, "Foobar"
253256
-- email
257+
, "git email"
254258
255259
-- homepage
256260
, "qux.com"
@@ -338,8 +342,10 @@ createProjectTest pkgIx srcDb = testGroup "createProject tests"
338342
-- license
339343
, "3"
340344
-- author
345+
, "git username"
341346
, "Foobar"
342347
-- email
348+
, "git email"
343349
344350
-- homepage
345351
, "qux.com"
@@ -414,8 +420,10 @@ createProjectTest pkgIx srcDb = testGroup "createProject tests"
414420
-- license
415421
, "3"
416422
-- author
423+
, "git username"
417424
, "Foobar"
418425
-- email
426+
, "git email"
419427
420428
-- homepage
421429
, "qux.com"
@@ -504,8 +512,10 @@ createProjectTest pkgIx srcDb = testGroup "createProject tests"
504512
-- license
505513
, "3"
506514
-- author
515+
, "git username"
507516
, "Foobar"
508517
-- email
518+
, "git email"
509519
510520
-- homepage
511521
, "qux.com"
@@ -579,8 +589,10 @@ createProjectTest pkgIx srcDb = testGroup "createProject tests"
579589
-- license
580590
, "3"
581591
-- author
592+
, "git username"
582593
, "Foobar"
583594
-- email
595+
, "git email"
584596
585597
-- homepage
586598
, "qux.com"
@@ -660,8 +672,10 @@ createProjectTest pkgIx srcDb = testGroup "createProject tests"
660672
-- license
661673
, "3"
662674
-- author
675+
, "git username"
663676
, "Foobar"
664677
-- email
678+
, "git email"
665679
666680
-- homepage
667681
, "qux.com"
@@ -728,7 +742,9 @@ fileCreatorTests pkgIx srcDb _pkgName = testGroup "generators"
728742
, "y" -- "yes to prompt internal to package name"
729743
, "0.2.0.1" -- package version
730744
, "2" -- pick the second license in the list
745+
, "git username" -- name guessed by calling "git config user.name"
731746
, "Foobar" -- author name
747+
, "git email" -- email guessed by calling "git config user.email"
732748
, "[email protected]" -- maintainer email
733749
, "qux.com" -- package homepage
734750
, "Qux's package" -- package synopsis
@@ -834,10 +850,14 @@ interactiveTests srcDb = testGroup "Check top level getter functions"
834850
, testSimplePrompt "2" synopsisPrompt
835851
"Resistance is futile, you will be assimilated" ["Resistance is futile, you will be assimilated"]
836852
]
837-
, testSimplePrompt "Check authorPrompt output" authorPrompt
838-
"Foobar" ["Foobar"]
839-
, testSimplePrompt "Check emailPrompt output" emailPrompt
840-
853+
, testSimplePrompt "Check authorPrompt output (name supplied by the user)" authorPrompt
854+
"Foobar" ["git username", "Foobar"]
855+
, testSimplePrompt "Check authorPrompt output (name guessed from git config)" authorPrompt
856+
"git username" ["git username", ""]
857+
, testSimplePrompt "Check emailPrompt output (email supplied by the user)" emailPrompt
858+
859+
, testSimplePrompt "Check emailPrompt output (email guessed from git config)" emailPrompt
860+
"git@email" ["git@email", ""]
841861
, testSimplePrompt "Check homepagePrompt output" homepagePrompt
842862
"qux.com" ["qux.com"]
843863
, testSimplePrompt "Check testDirsPrompt output" testDirsPrompt

changelog.d/issue-8255

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
synopsis: cabal init -i should autodetect author name and maintainer email (fix #8255)
2+
packages: cabal-install
3+
issues: #8255
4+
prs: #8267

0 commit comments

Comments
 (0)