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

Add global configuration option for non-interactive cabal init. #5825

Merged
merged 1 commit into from
Jan 15, 2019
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
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",
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if toSavedConfig would be better if this was an explicit list of what to include in the global config instead of an exclude list. In this case non-interactive is the only thing (at this point) from InitFlags that we want to be able to configure in ~/.cabal/config. Using an exclude list also introduces the possibility of newly added flags sneaking into the global config. Just a thought.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. We could also do something like IncludeAll | IncludeWhiteList [FlagName].

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added to my TODO list :)

"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