Skip to content

Commit

Permalink
[#303] Add noUpload option to toml config (#306)
Browse files Browse the repository at this point in the history
Resolves #303
  • Loading branch information
vrom911 authored and chshersh committed Apr 9, 2019
1 parent de75eb2 commit 8ba6fdd
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 12 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ Here is the list of the options that can be configured to suit your needs. If op
| `ghcVersions` | [GHC] | `summoner` uses default `GHC-8.6.4`. However, additionally you can specify other versions. For each version `x.y.z` the `stack-x.y.z.yaml` will be created. |
| `github` | Bool | Turn on `GitHub` integration by default? |
| `gitignore` | [Text] | List of files you want added to the default `.gitignore`. (Ignored if `github = false`) |
| `noUpload` | Bool | Do not upload to GitHub, but create all GitHub related files if specified (Ignored if `github = false`) |
| `private` | Bool | Create private repository by default? (Ignored if `github = false`) |
| `travis` | Bool | Turn on `Travis` integration by default? (Ignored if `github = false`) |
| `appveyor` | Bool | Turn on `AppVeyor` integration by default? (Ignored if `github = false`) |
Expand Down
2 changes: 2 additions & 0 deletions summoner-cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ The changelog is available [on GitHub][2].
Support build with `cabal-install` on the AppVeyor CI.
* [#261](https://github.com/kowainik/summoner/issues/261):
Guess author login, name and email from `.gitconfig`.
* [#303](https://github.com/kowainik/summoner/issues/303):
Add option 'noUpload' to TOML config file.

## 1.2.0 — Nov 30, 2018

Expand Down
9 changes: 4 additions & 5 deletions summoner-cli/src/Summoner/CLI.hs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ runNew newOpts@NewOpts{..} = do
-- get the final config
finalConfig <- getFinalConfig newOpts
-- Generate the project.
generateProject newOptsNoUpload newOptsOffline newOptsProjectName finalConfig
generateProject newOptsOffline newOptsProjectName finalConfig

-- | By the given 'NewOpts' return the final configurations.
getFinalConfig :: NewOpts -> IO Config
Expand Down Expand Up @@ -216,7 +216,6 @@ data Command
data NewOpts = NewOpts
{ newOptsProjectName :: Text -- ^ project name
, newOptsIgnoreFile :: Bool -- ^ ignore all config files if 'True'
, newOptsNoUpload :: Bool -- ^ don't upload to github
, newOptsOffline :: Bool -- ^ Offline mode
, newOptsConfigFile :: Maybe FilePath -- ^ file with custom configuration
, newOptsCliConfig :: PartialConfig -- ^ config gathered during CLI
Expand Down Expand Up @@ -327,7 +326,7 @@ newP :: Parser Command
newP = do
newOptsProjectName <- strArgument (metavar "PROJECT_NAME")
newOptsIgnoreFile <- ignoreFileP
newOptsNoUpload <- noUploadP
noUpload <- noUploadP
newOptsOffline <- offlineP
newOptsConfigFile <- optional fileP
cabal <- cabalP
Expand All @@ -338,11 +337,11 @@ newP = do
without <- optional withoutP

pure $ New $ NewOpts
{ newOptsNoUpload = newOptsNoUpload || newOptsOffline
, newOptsCliConfig = (maybeToMonoid $ with <> without)
{ newOptsCliConfig = (maybeToMonoid $ with <> without)
{ cPrelude = Last $ CustomPrelude <$> preludePack <*> preludeMod
, cCabal = cabal
, cStack = stack
, cNoUpload = Any $ noUpload || newOptsOffline
}
, ..
}
Expand Down
7 changes: 7 additions & 0 deletions summoner-cli/src/Summoner/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ data ConfigP (p :: Phase) = Config
, cGitignore :: ![Text]
, cStylish :: !(Last Source)
, cContributing :: !(Last Source)
, cNoUpload :: !Any -- ^ Do not upload to the GitHub (even if enabled)
} deriving (Generic)

deriving instance
Expand Down Expand Up @@ -128,6 +129,7 @@ defaultConfig = Config
, cGitignore = []
, cStylish = Last Nothing
, cContributing = Last Nothing
, cNoUpload = Any False
}

-- | Identifies how to read 'Config' data from the @.toml@ file.
Expand Down Expand Up @@ -155,10 +157,14 @@ configT = Config
<*> textArr "gitignore" .= cGitignore
<*> lastT sourceT "stylish" .= cStylish
<*> lastT sourceT "contributing" .= cContributing
<*> anyT "noUpload" .= cNoUpload
where
lastT :: (Key -> TomlCodec a) -> Key -> TomlCodec (Last a)
lastT codec = Toml.dimap getLast Last . Toml.dioptional . codec

anyT :: Key -> TomlCodec Any
anyT = Toml.dimap (Just . getAny) (Any . fromMaybe False) . Toml.dioptional . Toml.bool

_GhcVer :: TomlBiMap GhcVer Toml.AnyValue
_GhcVer = Toml._TextBy showGhcVer (maybeToRight "Wrong GHC version" . parseGhcVer)

Expand Down Expand Up @@ -215,6 +221,7 @@ finalise Config{..} = Config
<*> pure cGitignore
<*> pure cStylish
<*> pure cContributing
<*> pure cNoUpload
where
fin name = maybe (Failure ["Missing field: " <> name]) Success . getLast

Expand Down
10 changes: 7 additions & 3 deletions summoner-cli/src/Summoner/Project.hs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,11 @@ import Summoner.Tree (showBoldTree, traverseTree)

-- | Generate the project.
generateProject
:: Bool -- ^ @noUpload@ option (to not upload to @Github@).
-> Bool -- ^ @offline@ mode option
:: Bool -- ^ @offline@ mode option
-> Text -- ^ Given project name.
-> Config -- ^ Given configurations.
-> IO ()
generateProject settingsNoUpload isOffline projectName Config{..} = do
generateProject isOffline projectName Config{..} = do
unless (null cWarnings) $
warningMessage "Please, rename 'warnings' field if you use one, it will be removed in the very next release. Use 'ghc-options' instead."

Expand Down Expand Up @@ -70,6 +69,11 @@ generateProject settingsNoUpload isOffline projectName Config{..} = do

settingsGitHub <- decisionToBool cGitHub
(YesNoPrompt "GitHub integration" "Do you want to create a GitHub repository?")

let settingsNoUpload = getAny cNoUpload
when settingsNoUpload $ do
infoMessage "'No upload' option is selected. The project won't be uploaded to GitHub."
infoMessage "Use 'hub' and 'git' commands manually in order to upload the project to GitHub"
settingsPrivate <- decisionIf
(settingsGitHub && not settingsNoUpload)
(YesNoPrompt "private repository" "Create as a private repository (Requires a GitHub private repo plan)?")
Expand Down
1 change: 1 addition & 0 deletions summoner-cli/test/Test/TomlSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,5 @@ genPartialConfig = do
cGitignore <- genTextArr
cStylish <- Last <$> Gen.maybe genSource
cContributing <- Last <$> Gen.maybe genSource
cNoUpload <- Any <$> Gen.bool
pure Config{..}
1 change: 0 additions & 1 deletion summoner-tui/src/Summoner/Tui.hs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ summonTuiNew newOpts@NewOpts{..} = do
configFilePath <- findConfigFile
let initialKit = configToSummonKit
newOptsProjectName
newOptsNoUpload
newOptsOffline
configFilePath
finalConfig
Expand Down
5 changes: 2 additions & 3 deletions summoner-tui/src/Summoner/Tui/Kit.hs
Original file line number Diff line number Diff line change
Expand Up @@ -223,12 +223,11 @@ finalSettings sk = do
-- | Gets the initial 'SummonKit' from the given 'Config'.
configToSummonKit
:: Text -- ^ Given project name
-> Bool -- ^ @noUpload@ option (to not upload to @Github@).
-> Bool -- ^ @offline@ mode option
-> Maybe FilePath -- ^ Configuration file used
-> Config -- ^ Given configurations.
-> SummonKit
configToSummonKit cRepo cNoUpload cOffline cConfigFile Config{..} = SummonKit
configToSummonKit cRepo cOffline cConfigFile Config{..} = SummonKit
{ summonKitUser = User
{ userOwner = cOwner
, userFullName = cFullName
Expand All @@ -253,7 +252,7 @@ configToSummonKit cRepo cNoUpload cOffline cConfigFile Config{..} = SummonKit
, summonKitStack = kitStack
, summonKitGitHub = GitHub
{ gitHubEnabled = cGitHub /= Nop
, gitHubNoUpload = cNoUpload || cOffline
, gitHubNoUpload = getAny cNoUpload || cOffline
, gitHubPrivate = toBool cPrivate
, gitHubTravis = (cGitHub /= Nop) && (cTravis /= Nop)
, gitHubAppVeyor = toBool cAppVey && kitStack
Expand Down

0 comments on commit 8ba6fdd

Please sign in to comment.