File tree 5 files changed +33
-20
lines changed
src/Distribution/Client/Init
tests/UnitTests/Distribution/Client/Init 5 files changed +33
-20
lines changed Original file line number Diff line number Diff line change @@ -355,14 +355,10 @@ licensePrompt flags = getLicense flags $ do
355
355
else fmap prettyShow knownLicenses
356
356
357
357
authorPrompt :: Interactive m => InitFlags -> m String
358
- authorPrompt flags = getAuthor flags $ do
359
- name <- guessAuthorName
360
- promptStr " Author name" (DefaultPrompt name)
358
+ authorPrompt flags = getAuthor flags $ guessAuthorName >>= promptOrDefault " Author name"
361
359
362
360
emailPrompt :: Interactive m => InitFlags -> m String
363
- emailPrompt flags = getEmail flags $ do
364
- email' <- guessAuthorEmail
365
- promptStr " Maintainer email" (DefaultPrompt email')
361
+ emailPrompt flags = getEmail flags $ guessAuthorEmail >>= promptOrDefault " Maintainer email"
366
362
367
363
homepagePrompt :: Interactive m => InitFlags -> m String
368
364
homepagePrompt flags = getHomepage flags $
@@ -467,3 +463,6 @@ srcDirsPrompt flags = getSrcDirs flags $ do
467
463
True
468
464
469
465
return [dir]
466
+
467
+ promptOrDefault :: Interactive m => String -> Maybe String -> m String
468
+ promptOrDefault s = maybe (promptStr s MandatoryPrompt ) (promptStr s . DefaultPrompt )
Original file line number Diff line number Diff line change @@ -274,14 +274,16 @@ licenseHeuristics :: Interactive m => InitFlags -> m SpecLicense
274
274
licenseHeuristics flags = getLicense flags $ guessLicense flags
275
275
276
276
-- | The author's name. Prompt, or try to guess from an existing
277
- -- darcs repo.
277
+ -- git repo.
278
278
authorHeuristics :: Interactive m => InitFlags -> m String
279
- authorHeuristics flags = getAuthor flags guessAuthorEmail
279
+ authorHeuristics flags = guessAuthorName >>=
280
+ maybe (getAuthor flags $ return " Unknown" ) (getAuthor flags . return )
280
281
281
282
-- | The author's email. Prompt, or try to guess from an existing
282
- -- darcs repo.
283
+ -- git repo.
283
284
emailHeuristics :: Interactive m => InitFlags -> m String
284
- emailHeuristics flags = getEmail flags guessAuthorName
285
+ emailHeuristics flags = guessAuthorEmail >>=
286
+ maybe (getEmail flags $ return " Unknown" ) (getEmail flags . return )
285
287
286
288
-- | Prompt for a homepage URL for the package.
287
289
homepageHeuristics :: Interactive m => InitFlags -> m String
Original file line number Diff line number Diff line change @@ -151,18 +151,23 @@ guessSourceDirectories flags = do
151
151
True -> [" src" ]
152
152
153
153
-- | Guess author and email using git configuration options.
154
- guessAuthorName :: Interactive m => m String
154
+ guessAuthorName :: Interactive m => m ( Maybe String )
155
155
guessAuthorName = guessGitInfo " user.name"
156
156
157
- guessAuthorEmail :: Interactive m => m String
157
+ guessAuthorEmail :: Interactive m => m ( Maybe String )
158
158
guessAuthorEmail = guessGitInfo " user.email"
159
159
160
- guessGitInfo :: Interactive m => String -> m String
160
+ guessGitInfo :: Interactive m => String -> m ( Maybe String )
161
161
guessGitInfo target = do
162
- info <- readProcessWithExitCode " git" [" config" , " --local" , target] " "
163
- if null $ snd' info
164
- then trim . snd' <$> readProcessWithExitCode " git" [" config" , " --global" , target] " "
165
- else return . trim $ snd' info
162
+ localInfo <- readProcessWithExitCode " git" [" config" , " --local" , target] " "
163
+ if null $ snd' localInfo
164
+ then do
165
+ globalInfo <- readProcessWithExitCode " git" [" config" , " --global" , target] " "
166
+ case fst' globalInfo of
167
+ ExitSuccess -> return $ Just (trim $ snd' globalInfo)
168
+ _ -> return Nothing
169
+ else return $ Just (trim $ snd' localInfo)
166
170
167
171
where
172
+ fst' (x, _, _) = x
168
173
snd' (_, x, _) = x
Original file line number Diff line number Diff line change @@ -44,7 +44,9 @@ tests _v _initFlags comp pkgIx srcDb =
44
44
}
45
45
inputs =
46
46
-- createProject stuff
47
- [ " True"
47
+ [ " Foobar"
48
+
49
+ , " True"
48
50
, " [\" quxTest/Main.hs\" ]"
49
51
-- writeProject stuff
50
52
-- writeLicense
Original file line number Diff line number Diff line change @@ -73,7 +73,9 @@ driverFunctionTest pkgIx srcDb comp = testGroup "createProject"
73
73
, dependencies = Flag []
74
74
}
75
75
inputs = NEL. fromList
76
- [ " True"
76
+ [" Foobar"
77
+
78
+ , " True"
77
79
, " [\" quxTest/Main.hs\" ]"
78
80
]
79
81
@@ -149,8 +151,11 @@ driverFunctionTest pkgIx srcDb comp = testGroup "createProject"
149
151
, dependencies = Flag []
150
152
}
151
153
inputs = NEL. fromList
154
+
155
+ [ " Foobar"
156
+
152
157
-- extra sources
153
- [ " [\" CHANGELOG.md\" ]"
158
+ , " [\" CHANGELOG.md\" ]"
154
159
-- lib other modules
155
160
, " False"
156
161
-- exe other modules
You can’t perform that action at this time.
0 commit comments