added hint from git config

This commit is contained in:
Yann Esposito (Yogsototh) 2013-11-21 14:53:04 +01:00
parent 7143d8406c
commit 7ca9c497f4
2 changed files with 42 additions and 11 deletions

View file

@ -4,7 +4,7 @@ relaunchCompilation() {
while read line; do while read line; do
if (( $( print -- $line | grep '.cabal-sandbox' | wc -l) == 0 )); then if (( $( print -- $line | grep '.cabal-sandbox' | wc -l) == 0 )); then
print "$line" print "$line"
cabal install cabal install && \
./.cabal-sandbox/bin/test-holy-project ./.cabal-sandbox/bin/test-holy-project
fi fi
done done

View file

@ -3,7 +3,7 @@ module Main where
-- Project name manipulation -- Project name manipulation
import Data.Char (toUpper,toLower,isLetter,isNumber) import Data.Char (toUpper,toLower,isLetter,isNumber)
import Data.List (intersperse) import Data.List (intersperse,foldl')
import Data.List.Split import Data.List.Split
-- Get current year for the License -- Get current year for the License
import Data.Time.Clock import Data.Time.Clock
@ -24,6 +24,9 @@ import System.FilePath.Posix (takeDirectory,(</>))
import System.Cmd (system) import System.Cmd (system)
-- Random error message :) -- Random error message :)
import System.Random import System.Random
--- Environment variable
import System.Environment (getEnv)
import Data.Maybe (fromJust)
-- Get external file of package -- Get external file of package
import Paths_holy_project import Paths_holy_project
@ -65,15 +68,18 @@ ioassert False str = holyError str
main :: IO () main :: IO ()
main = do main = do
intro intro
project <- ask "project name" home <- getEnv "HOME"
gitconfig <- readFile $ home ++ "/.gitconfig"
let (name,email) = getNameAndMail gitconfig
project <- ask "project name" Nothing
ioassert (checkProjectName project) ioassert (checkProjectName project)
"Use only letters, numbers, spaces ans dashes please" "Use only letters, numbers, spaces ans dashes please"
let projectname = projectNameFromString project let projectname = projectNameFromString project
modulename = capitalize project modulename = capitalize project
in_author <- ask "name" in_author <- ask "name" name
in_email <- ask "email" in_email <- ask "email" email
in_ghaccount <- ask "github account" in_ghaccount <- ask "github account" Nothing
in_synopsis <- ask "project in less than a dozen word?" in_synopsis <- ask "project in less than a dozen word?" Nothing
current_year <- getCurrentYear current_year <- getCurrentYear
createProject $ Project projectname modulename in_author in_email createProject $ Project projectname modulename in_author in_email
in_ghaccount in_synopsis current_year in_ghaccount in_synopsis current_year
@ -126,14 +132,14 @@ end = do
you "Well, you have to know these things when you're a king, you know." you "Well, you have to know these things when you're a king, you know."
-- | Ask for some info and returns it -- | Ask for some info and returns it
ask :: String -> IO String ask :: String -> Maybe String -> IO String
ask info = do ask info hint = do
bk $ "What is your " ++ info ++ "?" bk $ "What is your " ++ info ++ "?" ++ (maybe "" (\h -> " ("++h++")") hint)
putStr "> " putStr "> "
hFlush stdout hFlush stdout
answer <- getLine answer <- getLine
putStrLn "" putStrLn ""
return answer return $ if (answer == "") && (hint /= Nothing) then fromJust hint else answer
-- | verify if project is conform -- | verify if project is conform
checkProjectName :: String -> Bool checkProjectName :: String -> Bool
@ -187,3 +193,28 @@ createProject p = do
_ <- system "cabal test" _ <- system "cabal test"
_ <- system $ "./.cabal-sandbox/bin/test-" ++ (projectName p) _ <- system $ "./.cabal-sandbox/bin/test-" ++ (projectName p)
return () return ()
getNameAndMail :: String -> (Maybe String,Maybe String)
getNameAndMail gitConfigContent = (name,email)
where
conflines :: [[String]]
conflines = map words (lines gitConfigContent)
name :: Maybe String
name = foldl' mMerge Nothing (map getName conflines)
email :: Maybe String
email = foldl' mMerge Nothing (map getEmail conflines)
getName :: [String] -> Maybe String
getName ("name":"=":xs) = Just (concat (intersperse " " xs))
getName _ = Nothing
getEmail :: [String] -> Maybe String
getEmail ("email":"=":xs) = Just (concat (intersperse " " xs))
getEmail _ = Nothing
mMerge :: Maybe String -> Maybe String -> Maybe String
mMerge Nothing (Just x) = Just x
mMerge Nothing Nothing = Nothing
mMerge (Just x) _ = Just x