diff --git a/cabal-install/src/Distribution/Client/Init/Interactive/Command.hs b/cabal-install/src/Distribution/Client/Init/Interactive/Command.hs index 7e56bbce83c811da3a793524b0b48cdcd4a1775d..3e5c9f1c5ecba3f0a09bf6fc27782f9d86f1c951 100644 --- a/cabal-install/src/Distribution/Client/Init/Interactive/Command.hs +++ b/cabal-install/src/Distribution/Client/Init/Interactive/Command.hs @@ -53,6 +53,7 @@ import Distribution.Client.Init.FlagExtractors import Distribution.Client.Init.Prompt import Distribution.Client.Init.Types import Distribution.Client.Init.Utils +import Distribution.Client.Init.NonInteractive.Heuristics (guessAuthorName, guessAuthorEmail) import Distribution.FieldGrammar.Newtypes (SpecLicense(..)) import Distribution.Simple.Setup (Flag(..), fromFlagOrDefault) import Distribution.Simple.PackageIndex (InstalledPackageIndex) @@ -355,12 +356,14 @@ licensePrompt flags = getLicense flags $ do else fmap prettyShow knownLicenses authorPrompt :: Interactive m => InitFlags -> m String -authorPrompt flags = getAuthor flags $ - promptStr "Author name" OptionalPrompt +authorPrompt flags = getAuthor flags $ do + name <- guessAuthorName + promptStr "Author name" (DefaultPrompt name) emailPrompt :: Interactive m => InitFlags -> m String -emailPrompt flags = getEmail flags $ - promptStr "Maintainer email" OptionalPrompt +emailPrompt flags = getEmail flags $ do + email' <- guessAuthorEmail + promptStr "Maintainer email" (DefaultPrompt email') homepagePrompt :: Interactive m => InitFlags -> m String homepagePrompt flags = getHomepage flags $ diff --git a/cabal-install/tests/UnitTests/Distribution/Client/Init/Golden.hs b/cabal-install/tests/UnitTests/Distribution/Client/Init/Golden.hs index 4e02aa3c74d4a57f933b383a186f95a0efb9740b..789f110c63c3ac831c48e1f7ec8ab8ff51cfe4cb 100644 --- a/cabal-install/tests/UnitTests/Distribution/Client/Init/Golden.hs +++ b/cabal-install/tests/UnitTests/Distribution/Client/Init/Golden.hs @@ -340,7 +340,9 @@ pkgArgs = fromList , "y" , "0.1.0.0" , "2" + , "git username" , "foo-kmett" + , "git email" , "foo-kmett@kmett.kmett" , "home" , "synopsis" diff --git a/cabal-install/tests/UnitTests/Distribution/Client/Init/Interactive.hs b/cabal-install/tests/UnitTests/Distribution/Client/Init/Interactive.hs index 9a998e1f3369362c11df4073b7abb03f284802d0..f8393d55a61f8561592ce8168ddd66c3773e6317 100644 --- a/cabal-install/tests/UnitTests/Distribution/Client/Init/Interactive.hs +++ b/cabal-install/tests/UnitTests/Distribution/Client/Init/Interactive.hs @@ -145,8 +145,10 @@ createProjectTest pkgIx srcDb = testGroup "createProject tests" -- license , "3" -- author + , "git username" , "Foobar" -- email + , "git email" , "foobar@qux.com" -- homepage , "qux.com" @@ -249,8 +251,10 @@ createProjectTest pkgIx srcDb = testGroup "createProject tests" -- license , "3" -- author + , "git username" , "Foobar" -- email + , "git email" , "foobar@qux.com" -- homepage , "qux.com" @@ -338,8 +342,10 @@ createProjectTest pkgIx srcDb = testGroup "createProject tests" -- license , "3" -- author + , "git username" , "Foobar" -- email + , "git email" , "foobar@qux.com" -- homepage , "qux.com" @@ -414,8 +420,10 @@ createProjectTest pkgIx srcDb = testGroup "createProject tests" -- license , "3" -- author + , "git username" , "Foobar" -- email + , "git email" , "foobar@qux.com" -- homepage , "qux.com" @@ -504,8 +512,10 @@ createProjectTest pkgIx srcDb = testGroup "createProject tests" -- license , "3" -- author + , "git username" , "Foobar" -- email + , "git email" , "foobar@qux.com" -- homepage , "qux.com" @@ -579,8 +589,10 @@ createProjectTest pkgIx srcDb = testGroup "createProject tests" -- license , "3" -- author + , "git username" , "Foobar" -- email + , "git email" , "foobar@qux.com" -- homepage , "qux.com" @@ -660,8 +672,10 @@ createProjectTest pkgIx srcDb = testGroup "createProject tests" -- license , "3" -- author + , "git username" , "Foobar" -- email + , "git email" , "foobar@qux.com" -- homepage , "qux.com" @@ -728,7 +742,9 @@ fileCreatorTests pkgIx srcDb _pkgName = testGroup "generators" , "y" -- "yes to prompt internal to package name" , "0.2.0.1" -- package version , "2" -- pick the second license in the list + , "git username" -- name guessed by calling "git config user.name" , "Foobar" -- author name + , "git email" -- email guessed by calling "git config user.email" , "foobar@qux.com" -- maintainer email , "qux.com" -- package homepage , "Qux's package" -- package synopsis @@ -834,10 +850,14 @@ interactiveTests srcDb = testGroup "Check top level getter functions" , testSimplePrompt "2" synopsisPrompt "Resistance is futile, you will be assimilated" ["Resistance is futile, you will be assimilated"] ] - , testSimplePrompt "Check authorPrompt output" authorPrompt - "Foobar" ["Foobar"] - , testSimplePrompt "Check emailPrompt output" emailPrompt - "foobar@qux.com" ["foobar@qux.com"] + , testSimplePrompt "Check authorPrompt output (name supplied by the user)" authorPrompt + "Foobar" ["git username", "Foobar"] + , testSimplePrompt "Check authorPrompt output (name guessed from git config)" authorPrompt + "git username" ["git username", ""] + , testSimplePrompt "Check emailPrompt output (email supplied by the user)" emailPrompt + "foobar@qux.com" ["git email", "foobar@qux.com"] + , testSimplePrompt "Check emailPrompt output (email guessed from git config)" emailPrompt + "git@email" ["git@email", ""] , testSimplePrompt "Check homepagePrompt output" homepagePrompt "qux.com" ["qux.com"] , testSimplePrompt "Check testDirsPrompt output" testDirsPrompt diff --git a/changelog.d/issue-8255 b/changelog.d/issue-8255 new file mode 100644 index 0000000000000000000000000000000000000000..453203bf1ee5e567aa8c6fe1b6227f68497dec76 --- /dev/null +++ b/changelog.d/issue-8255 @@ -0,0 +1,4 @@ +synopsis: cabal init -i should autodetect author name and maintainer email (fix #8255) +packages: cabal-install +issues: #8255 +prs: #8267