Skip to content

Commit 9f73a6d

Browse files
committed
Add a 'cabal path' command.
1 parent eece442 commit 9f73a6d

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

cabal-install/src/Distribution/Client/Main.hs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import Distribution.Client.Setup
3636
, ReportFlags (..)
3737
, UploadFlags (..)
3838
, UserConfigFlags (..)
39+
, PathFlags (..)
3940
, actAsSetupCommand
4041
, benchmarkCommand
4142
, buildCommand
@@ -69,6 +70,7 @@ import Distribution.Client.Setup
6970
, unpackCommand
7071
, uploadCommand
7172
, userConfigCommand
73+
, pathCommand
7274
, withRepoContext
7375
)
7476
import Distribution.Simple.Setup
@@ -102,6 +104,9 @@ import Distribution.Client.Config
102104
, loadConfig
103105
, userConfigDiff
104106
, userConfigUpdate
107+
, defaultCacheDir
108+
, defaultLogsDir
109+
, defaultStoreDir
105110
)
106111
import qualified Distribution.Client.List as List
107112
( info
@@ -368,6 +373,7 @@ mainWorker args = do
368373
, regularCmd reportCommand reportAction
369374
, regularCmd initCommand initAction
370375
, regularCmd userConfigCommand userConfigAction
376+
, regularCmd pathCommand pathAction
371377
, regularCmd genBoundsCommand genBoundsAction
372378
, regularCmd CmdOutdated.outdatedCommand CmdOutdated.outdatedAction
373379
, wrapperCmd hscolourCommand hscolourVerbosity hscolourDistPref
@@ -1320,3 +1326,14 @@ manpageAction commands flags extraArgs _ = do
13201326
then dropExtension pname
13211327
else pname
13221328
manpageCmd cabalCmd commands flags
1329+
1330+
pathAction :: PathFlags -> [String] -> Action
1331+
pathAction pathflags _extraArgs _globalFlags = do
1332+
let verbosity = fromFlag (pathVerbosity pathflags)
1333+
cfg <- loadConfig verbosity mempty
1334+
putStrLn . ("cache-dir: "++) =<< maybe defaultCacheDir pure
1335+
(flagToMaybe $ globalCacheDir $ savedGlobalFlags cfg)
1336+
putStrLn . ("logs-dir: "++) =<< maybe defaultLogsDir pure
1337+
(flagToMaybe $ globalLogsDir $ savedGlobalFlags cfg)
1338+
putStrLn . ("store-dir: "++) =<< maybe defaultStoreDir pure
1339+
(flagToMaybe $ globalStoreDir $ savedGlobalFlags cfg)

cabal-install/src/Distribution/Client/Setup.hs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ module Distribution.Client.Setup
8585
, cleanCommand
8686
, copyCommand
8787
, registerCommand
88+
, PathFlags (..)
89+
, pathCommand
8890
, liftOptions
8991
, yesNoOpt
9092
) where
@@ -3322,6 +3324,42 @@ userConfigCommand =
33223324

33233325
-- ------------------------------------------------------------
33243326

3327+
-- * Dirs
3328+
3329+
-- ------------------------------------------------------------
3330+
3331+
data PathFlags = PathFlags {
3332+
pathVerbosity :: Flag Verbosity
3333+
} deriving Generic
3334+
3335+
instance Monoid PathFlags where
3336+
mempty = PathFlags {
3337+
pathVerbosity = toFlag normal
3338+
}
3339+
mappend = (<>)
3340+
3341+
instance Semigroup PathFlags where
3342+
(<>) = gmappend
3343+
3344+
pathCommand :: CommandUI PathFlags
3345+
pathCommand = CommandUI {
3346+
commandName = "path",
3347+
commandSynopsis = "Display the directories used by cabal",
3348+
commandDescription = Just $ \_ -> wrapText $
3349+
"This command prints the directories that are used by cabal,"
3350+
++ " taking into account the contents of the configuration file and any"
3351+
++ " environment variables.",
3352+
3353+
commandNotes = Nothing,
3354+
commandUsage = \pname -> "Usage: " ++ pname ++ " path\n",
3355+
commandDefaultFlags = mempty,
3356+
commandOptions = \ _ -> [
3357+
optionVerbosity pathVerbosity (\v flags -> flags { pathVerbosity = v })]
3358+
}
3359+
3360+
3361+
-- ------------------------------------------------------------
3362+
33253363
-- * GetOpt Utils
33263364

33273365
-- ------------------------------------------------------------

0 commit comments

Comments
 (0)