Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#96] Add option to choose cabal or stack or both #106

Merged
merged 3 commits into from
Jul 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
UseTravis-specific env variable `TRAVIS_BUILD_DIR` in created travis file.
* [#97](https://github.com/kowainik/summoner/issues/97):
Add cabal to created travis file.
* [#96](https://github.com/kowainik/summoner/issues/96):
Add option to choose `cabal`, `stack` or both.

1.0.4
=====
Expand Down
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ Here is the list of the options that could be configured for your needs:

###### Global keys

* `cabal` – `true` if you want to build you project with `cabal`,
`false` if you don't. If not specified it would be asked during each run of the `summoner`.
* `stack` – `true` if you want to build your project with `stack`,
`false` if you don't. If not specified it would be asked during each run of the `summoner`.
* `owner` – `GitHub` login.
* `fullName` – full name.
* `email` – e-mail address.
Expand Down Expand Up @@ -114,13 +118,16 @@ The other way to specify some particular `.toml` file is `summon PROJECTNAME --f
See the basic usage syntax below (you can check it out with `summon --help` command):

```
summon PROJECT_NAME [with [OPTIONS]] [without [OPTIONS]]
summon PROJECT_NAME [--cabal] [--stack]
[with [OPTIONS]] [without [OPTIONS]]
[-f|--file FILENAME] [--prelude-package PACKAGE_NAME]
[--prelude-module MODULE_NAME]

Available global options:
-h, --help Show this help text
-v, --version Show summoner's version
--cabal Cabal support for the project
--stack Stack support for the project
-f, --file FILENAME Path to the toml file with configurations. If not
specified '~/.summoner.toml' will be used if present
--prelude-package PACKAGE_NAME
Expand Down
14 changes: 14 additions & 0 deletions src/Summoner/CLI.hs
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,21 @@ preludeModP = strOption
<> metavar "MODULE_NAME"
<> help "Name for the module of the custom prelude to use in the project"

cabalP :: Parser Decision
cabalP = flag Idk Yes
$ long "cabal"
<> help "Cabal support for the project"

stackP :: Parser Decision
stackP = flag Idk Yes
$ long "stack"
<> help "Stack support for the project"

optsP :: Parser InitOpts
optsP = do
projectName <- strArgument (metavar "PROJECT_NAME")
cabal <- cabalP
stack <- stackP
with <- optional withP
without <- optional withoutP
file <- optional fileP
Expand All @@ -199,6 +211,8 @@ optsP = do
pure $ InitOpts projectName file
$ (maybeToMonoid $ with <> without)
{ cPrelude = Last $ Prelude <$> preludePack <*> preludeMod
, cCabal = cabal
, cStack = stack
}

versionP :: Parser (a -> a)
Expand Down
10 changes: 9 additions & 1 deletion src/Summoner/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ data ConfigP (p :: Phase) = Config
, cEmail :: p :- Text
, cLicense :: p :- License
, cGhcVer :: p :- [GhcVer]
, cCabal :: Decision
, cStack :: Decision
, cGitHub :: Decision
, cTravis :: Decision
, cAppVey :: Decision
Expand Down Expand Up @@ -91,6 +93,8 @@ defaultConfig = Config
, cEmail = Last (Just "xrom.xkov@gmail.com")
, cLicense = Last (Just $ License "MIT")
, cGhcVer = Last (Just [])
, cCabal = Idk
, cStack = Idk
, cGitHub = Idk
, cTravis = Idk
, cAppVey = Idk
Expand All @@ -112,6 +116,8 @@ configT = Config
<*> lastT Toml.text "email" .= cEmail
<*> lastT license "license" .= cLicense
<*> lastT ghcVerArr "ghcVersions" .= cGhcVer
<*> decision "cabal" .= cCabal
<*> decision "stack" .= cStack
<*> decision "github" .= cGitHub
<*> decision "travis" .= cTravis
<*> decision "appveyor" .= cAppVey
Expand Down Expand Up @@ -169,7 +175,9 @@ finalise Config{..} = Config
<*> fin "fullName" cFullName
<*> fin "email" cEmail
<*> fin "license" cLicense
<*> fin "ghcersions" cGhcVer
<*> fin "ghcVersions" cGhcVer
<*> pure cCabal
<*> pure cStack
<*> pure cGitHub
<*> pure cTravis
<*> pure cAppVey
Expand Down
30 changes: 27 additions & 3 deletions src/Summoner/Project.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@ import NeatInterpolation (text)
import System.Info (os)
import System.Process (readProcess)

import Summoner.Ansi (infoMessage, successMessage)
import Summoner.Ansi (errorMessage, infoMessage, successMessage)
import Summoner.Config (Config, ConfigP (..))
import Summoner.Default (currentYear, defaultGHC)
import Summoner.License (License (..), customizeLicense, githubLicenseQueryNames, licenseNames)
import Summoner.Process ()
import Summoner.ProjectData (CustomPrelude (..), Decision (..), ProjectData (..), parseGhcVer,
showGhcVer, supportedGhcVers)
import Summoner.Question (checkUniqueName, choose, chooseYesNo, chooseYesNoBool, falseMessage,
query, queryDef, queryManyRepeatOnFail, trueMessage)
query, queryDef, queryManyRepeatOnFail, targetMessageWithText,
trueMessage)
import Summoner.Template (createStackTemplate)
import Summoner.Text (intercalateMap, packageToModule)
import Summoner.Tree (showTree, traverseTree)
Expand All @@ -39,6 +40,9 @@ decisionToBool decision target = case decision of
generateProject :: Text -> Config -> IO ()
generateProject projectName Config{..} = do
repo <- checkUniqueName projectName
-- decide cabal stack or both
(cabal, stack) <- getCabalStack (cCabal, cStack)

owner <- queryDef "Repository owner: " cOwner
description <- query "Short project description: "
nm <- queryDef "Author: " cFullName
Expand Down Expand Up @@ -67,7 +71,7 @@ generateProject projectName Config{..} = do
-- Library/Executable/Tests/Benchmarks flags
github <- decisionToBool cGitHub "GitHub integration"
travis <- ifGithub github "Travis CI integration" cTravis
appVey <- ifGithub github "AppVeyor CI integration" cAppVey
appVey <- ifGithub (stack && github) "AppVeyor CI integration" cAppVey
privat <- ifGithub github "private repository" cPrivate
script <- decisionToBool cScript "build script"
isLib <- decisionToBool cLib "library target"
Expand Down Expand Up @@ -165,3 +169,23 @@ generateProject projectName Config{..} = do
chooseYesNo "custom prelude" yesDo noDo
Last prelude@(Just (Prelude p _)) ->
prelude <$ successMessage ("Custom prelude " <> p <> " will be used in the project")

-- get what build tool to use in the project
-- If user chose only one during CLI, we assume to use only that one.
getCabalStack :: (Decision, Decision) -> IO (Bool, Bool)
getCabalStack = \case
(Idk, Idk) -> decisionToBool cCabal "cabal" >>= \c ->
if c then decisionToBool cStack "stack" >>= \s -> pure (c, s)
else stackMsg True >> pure (False, True)
(Nop, Nop) -> errorMessage "Neither cabal nor stack was chosen" >> exitFailure
(Yes, Yes) -> output (True, True)
(Yes, _) -> output (True, False)
(_, Yes) -> output (False, True)
(Nop, Idk) -> output (False, True)
(Idk, Nop) -> output (True, False)
where
output :: (Bool, Bool) -> IO (Bool, Bool)
output x@(c, s) = cabalMsg c >> stackMsg s >> pure x

cabalMsg c = targetMessageWithText c "Cabal" "used in this project"
stackMsg c = targetMessageWithText c "Stack" "used in this project"
2 changes: 2 additions & 0 deletions src/Summoner/ProjectData.hs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ data ProjectData = ProjectData
, base :: Text -- ^ Base library to use
, prelude :: Maybe CustomPrelude -- ^ custom prelude to be used
, extensions :: [Text] -- ^ default extensions
, cabal :: Bool
, stack :: Bool
} deriving (Show)

-- | Used for detecting the user decision during CLI input.
Expand Down
11 changes: 8 additions & 3 deletions src/Summoner/Question.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ module Summoner.Question
, queryManyRepeatOnFail
, checkUniqueName

, targetMessageWithText

, trueMessage
, falseMessage
) where
Expand Down Expand Up @@ -71,10 +73,13 @@ chooseYesNoBool :: Text -> IO Bool
chooseYesNoBool target = chooseYesNo target (pure True) (pure False)

targetMessage :: Bool -> Text -> IO Bool
targetMessage result target = do
targetMessage result target = targetMessageWithText result target "added to the project"

targetMessageWithText :: Bool -> Text -> Text -> IO Bool
targetMessageWithText result target text = do
let (color, actionResult) = if result
then (Green, " will be added to the project")
else (Cyan, " won't be added to the project")
then (Green, " will be " <> text)
else (Cyan, " won't be" <> text)

beautyPrint [italic, bold, setColor color] $ " " <> headToUpper target
beautyPrint [setColor color] actionResult
Expand Down
Loading