diff --git a/README.md b/README.md index facdf079..a86e8cf7 100644 --- a/README.md +++ b/README.md @@ -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`) | diff --git a/summoner-cli/CHANGELOG.md b/summoner-cli/CHANGELOG.md index f41902b8..75007341 100644 --- a/summoner-cli/CHANGELOG.md +++ b/summoner-cli/CHANGELOG.md @@ -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 diff --git a/summoner-cli/src/Summoner/CLI.hs b/summoner-cli/src/Summoner/CLI.hs index 9e814262..f2dbc20d 100644 --- a/summoner-cli/src/Summoner/CLI.hs +++ b/summoner-cli/src/Summoner/CLI.hs @@ -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 @@ -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 @@ -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 @@ -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 } , .. } diff --git a/summoner-cli/src/Summoner/Config.hs b/summoner-cli/src/Summoner/Config.hs index a8ab76b3..4e64c12a 100644 --- a/summoner-cli/src/Summoner/Config.hs +++ b/summoner-cli/src/Summoner/Config.hs @@ -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 @@ -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. @@ -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) @@ -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 diff --git a/summoner-cli/src/Summoner/Project.hs b/summoner-cli/src/Summoner/Project.hs index 43f2151d..c99a0168 100644 --- a/summoner-cli/src/Summoner/Project.hs +++ b/summoner-cli/src/Summoner/Project.hs @@ -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." @@ -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)?") diff --git a/summoner-cli/test/Test/TomlSpec.hs b/summoner-cli/test/Test/TomlSpec.hs index 0ad807f4..debb7c70 100644 --- a/summoner-cli/test/Test/TomlSpec.hs +++ b/summoner-cli/test/Test/TomlSpec.hs @@ -72,4 +72,5 @@ genPartialConfig = do cGitignore <- genTextArr cStylish <- Last <$> Gen.maybe genSource cContributing <- Last <$> Gen.maybe genSource + cNoUpload <- Any <$> Gen.bool pure Config{..} diff --git a/summoner-tui/src/Summoner/Tui.hs b/summoner-tui/src/Summoner/Tui.hs index 5cfc2d52..332bc725 100644 --- a/summoner-tui/src/Summoner/Tui.hs +++ b/summoner-tui/src/Summoner/Tui.hs @@ -71,7 +71,6 @@ summonTuiNew newOpts@NewOpts{..} = do configFilePath <- findConfigFile let initialKit = configToSummonKit newOptsProjectName - newOptsNoUpload newOptsOffline configFilePath finalConfig diff --git a/summoner-tui/src/Summoner/Tui/Kit.hs b/summoner-tui/src/Summoner/Tui/Kit.hs index 803cfeeb..10887c62 100644 --- a/summoner-tui/src/Summoner/Tui/Kit.hs +++ b/summoner-tui/src/Summoner/Tui/Kit.hs @@ -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 @@ -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