Skip to content

Commit

Permalink
Merge pull request #5825 from m-renaud/interactive-init-config
Browse files Browse the repository at this point in the history
Add global configuration option for non-interactive cabal init.
  • Loading branch information
23Skidoo authored Jan 15, 2019
2 parents 1feec33 + e29406c commit 5fbd32e
Show file tree
Hide file tree
Showing 3 changed files with 233 additions and 175 deletions.
54 changes: 54 additions & 0 deletions cabal-install/Distribution/Client/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,12 @@ import Distribution.Client.Types
)
import Distribution.Client.BuildReports.Types
( ReportLevel(..) )
import qualified Distribution.Client.Init.Types as IT
( InitFlags(..) )
import Distribution.Client.Setup
( GlobalFlags(..), globalCommand, defaultGlobalFlags
, ConfigExFlags(..), configureExOptions, defaultConfigExFlags
, initOptions
, InstallFlags(..), installOptions, defaultInstallFlags
, UploadFlags(..), uploadCommand
, ReportFlags(..), reportCommand
Expand Down Expand Up @@ -147,6 +150,7 @@ import GHC.Generics ( Generic )

data SavedConfig = SavedConfig {
savedGlobalFlags :: GlobalFlags,
savedInitFlags :: IT.InitFlags,
savedInstallFlags :: InstallFlags,
savedConfigureFlags :: ConfigFlags,
savedConfigureExFlags :: ConfigExFlags,
Expand All @@ -165,6 +169,7 @@ instance Monoid SavedConfig where
instance Semigroup SavedConfig where
a <> b = SavedConfig {
savedGlobalFlags = combinedSavedGlobalFlags,
savedInitFlags = combinedSavedInitFlags,
savedInstallFlags = combinedSavedInstallFlags,
savedConfigureFlags = combinedSavedConfigureFlags,
savedConfigureExFlags = combinedSavedConfigureExFlags,
Expand Down Expand Up @@ -246,6 +251,39 @@ instance Semigroup SavedConfig where
combine = combine' savedGlobalFlags
lastNonEmptyNL = lastNonEmptyNL' savedGlobalFlags

combinedSavedInitFlags = IT.InitFlags {
IT.nonInteractive = combine IT.nonInteractive,
IT.quiet = combine IT.quiet,
IT.packageDir = combine IT.packageDir,
IT.noComments = combine IT.noComments,
IT.minimal = combine IT.minimal,
IT.simpleProject = combine IT.simpleProject,
IT.packageName = combine IT.packageName,
IT.version = combine IT.version,
IT.cabalVersion = combine IT.cabalVersion,
IT.license = combine IT.license,
IT.author = combine IT.author,
IT.email = combine IT.email,
IT.homepage = combine IT.homepage,
IT.synopsis = combine IT.synopsis,
IT.category = combine IT.category,
IT.extraSrc = combineMonoid savedInitFlags IT.extraSrc,
IT.packageType = combine IT.packageType,
IT.mainIs = combine IT.mainIs,
IT.language = combine IT.language,
IT.exposedModules = combineMonoid savedInitFlags IT.exposedModules,
IT.otherModules = combineMonoid savedInitFlags IT.otherModules,
IT.otherExts = combineMonoid savedInitFlags IT.otherExts,
IT.dependencies = combineMonoid savedInitFlags IT.dependencies,
IT.sourceDirs = combineMonoid savedInitFlags IT.sourceDirs,
IT.buildTools = combineMonoid savedInitFlags IT.buildTools,
IT.initHcPath = combine IT.initHcPath,
IT.initVerbosity = combine IT.initVerbosity,
IT.overwrite = combine IT.overwrite
}
where
combine = combine' savedInitFlags

combinedSavedInstallFlags = InstallFlags {
installDocumentation = combine installDocumentation,
installHaddockIndex = combine installHaddockIndex,
Expand Down Expand Up @@ -754,6 +792,9 @@ commentSavedConfig = do
savedGlobalFlags = defaultGlobalFlags {
globalRemoteRepos = toNubList [defaultRemoteRepo]
},
savedInitFlags = mempty {
IT.nonInteractive = toFlag False
},
savedInstallFlags = defaultInstallFlags,
savedConfigureExFlags = defaultConfigExFlags {
configAllowNewer = Just (AllowNewer mempty),
Expand Down Expand Up @@ -873,6 +914,15 @@ configFieldDescriptions src =
configAllowNewer (\v flags -> flags { configAllowNewer = v })
]

++ toSavedConfig liftInitFlag
(initOptions ParseArgs)
["quiet", "no-comments", "minimal", "overwrite", "package-dir",
"packagedir", "package-name", "version", "cabal-version", "license",
"author", "email", "homepage", "synopsis", "category",
"extra-source-file", "lib", "exe", "libandexe", "simple",
"main-is", "language", "exposed-module", "extension", "dependency",
"source-dir", "build-tool", "with-compiler"] []

++ toSavedConfig liftInstallFlag
(installOptions ParseArgs)
["dry-run", "only", "only-dependencies", "dependencies-only"] []
Expand Down Expand Up @@ -980,6 +1030,10 @@ liftConfigExFlag :: FieldDescr ConfigExFlags -> FieldDescr SavedConfig
liftConfigExFlag = liftField
savedConfigureExFlags (\flags conf -> conf { savedConfigureExFlags = flags })

liftInitFlag :: FieldDescr IT.InitFlags -> FieldDescr SavedConfig
liftInitFlag = liftField
savedInitFlags (\flags conf -> conf { savedInitFlags = flags })

liftInstallFlag :: FieldDescr InstallFlags -> FieldDescr SavedConfig
liftInstallFlag = liftField
savedInstallFlags (\flags conf -> conf { savedInstallFlags = flags })
Expand Down
Loading

0 comments on commit 5fbd32e

Please sign in to comment.