Commit 059a6f1c authored by Ben Gamari's avatar Ben Gamari 🐢
Browse files

Skeleton of new-haddock

parent 9d25d064
{-# LANGUAGE NamedFieldPuns #-}
-- | cabal-install CLI command: haddock
--
module Distribution.Client.CmdHaddock (
haddockCommand,
haddockAction,
) where
import Distribution.Client.ProjectOrchestration
import Distribution.Client.ProjectConfig
import Distribution.Client.ProjectPlanning
( PackageTarget(..) )
import Distribution.Client.BuildTarget
( readUserBuildTargets )
import Distribution.Client.Setup
( GlobalFlags, ConfigFlags(..), ConfigExFlags, InstallFlags )
import qualified Distribution.Client.Setup as Client
import Distribution.Simple.Command
( CommandUI(..), usageAlternatives )
import Distribution.Simple.Setup
( HaddockFlags, fromFlagOrDefault )
import Distribution.Simple.Utils
( wrapText )
import Distribution.Verbosity
( normal )
import Control.Monad (unless, void)
haddockCommand :: CommandUI (ConfigFlags, ConfigExFlags, InstallFlags, HaddockFlags)
haddockCommand = Client.installCommand {
commandName = "new-haddock",
commandSynopsis = "Build Haddock documentation for the current project",
commandUsage = usageAlternatives "new-haddock" [ "[FLAGS] TARGET" ],
commandDescription = Just $ \_ -> wrapText $
"Build Haddock documentation for a Nix-local build project.",
commandNotes = Just $ \pname ->
"Examples:\n"
++ " " ++ pname ++ " new-haddock cname"
++ " Build documentation for the component named cname\n"
++ " " ++ pname ++ " new-haddock pkgname:cname"
++ " Build documentation for the component named cname in pkgname\n"
}
-- | The @haddock@ command is TODO.
--
-- For more details on how this works, see the module
-- "Distribution.Client.ProjectOrchestration"
--
haddockAction :: (ConfigFlags, ConfigExFlags, InstallFlags, HaddockFlags)
-> [String] -> GlobalFlags -> IO ()
haddockAction (configFlags, configExFlags, installFlags, haddockFlags)
targetStrings globalFlags = do
userTargets <- readUserBuildTargets targetStrings
buildCtx <-
runProjectPreBuildPhase
verbosity
( globalFlags, configFlags, configExFlags
, installFlags, haddockFlags )
PreBuildHooks {
hookPrePlanning = \_ _ _ -> return (),
hookSelectPlanSubset = \_ ->
-- When we interpret the targets on the command line, interpret them as
-- haddock targets
selectTargets
verbosity
HaddockDefaultComponents
(const HaddockDefaultComponents)
userTargets
False -- onlyDependencies, always False for haddock
}
--TODO: Hmm, but we don't have any targets. Currently this prints what we
-- would build if we were to build everything. Could pick implicit target like "."
--TODO: should we say what's in the project (+deps) as a whole?
printPlan
verbosity
buildCtx {
buildSettings = (buildSettings buildCtx) {
buildSettingDryRun = True
}
}
unless (buildSettingDryRun (buildSettings buildCtx)) $ void $
runProjectBuildPhase
verbosity
buildCtx
where
verbosity = fromFlagOrDefault normal (configVerbosity configFlags)
......@@ -77,6 +77,7 @@ import qualified Distribution.Client.CmdConfigure as CmdConfigure
import qualified Distribution.Client.CmdBuild as CmdBuild
import qualified Distribution.Client.CmdRepl as CmdRepl
import qualified Distribution.Client.CmdFreeze as CmdFreeze
import qualified Distribution.Client.CmdHaddock as CmdHaddock
import Distribution.Client.Install (install)
import Distribution.Client.Configure (configure, writeConfigFlags)
......@@ -277,6 +278,7 @@ mainWorker args = topHandler $
, regularCmd CmdBuild.buildCommand CmdBuild.buildAction
, regularCmd CmdRepl.replCommand CmdRepl.replAction
, regularCmd CmdFreeze.freezeCommand CmdFreeze.freezeAction
, regularCmd CmdHaddock.haddockCommand CmdHaddock.haddockAction
]
type Action = GlobalFlags -> IO ()
......
......@@ -271,6 +271,7 @@ executable cabal
Distribution.Client.CmdBuild
Distribution.Client.CmdConfigure
Distribution.Client.CmdFreeze
Distribution.Client.CmdHaddock
Distribution.Client.CmdRepl
Distribution.Client.Config
Distribution.Client.Configure
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment