From 9dc6113dd3d389f3c1aa4edf08626b5fe7bece54 Mon Sep 17 00:00:00 2001 From: Sibi Prabakaran Date: Mon, 25 Dec 2017 15:57:19 +0530 Subject: [PATCH] Port list-dependencies under new ls sub command Fixes #3669 --- src/Stack/Ls.hs | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/src/Stack/Ls.hs b/src/Stack/Ls.hs index f0589a1f8c..55ed946c09 100644 --- a/src/Stack/Ls.hs +++ b/src/Stack/Ls.hs @@ -5,6 +5,7 @@ module Stack.Ls ( lsCmd , lsParser + , listDependenciesCmd ) where import Control.Exception (Exception, throw) @@ -29,8 +30,10 @@ import Network.HTTP.Types.Header (hAccept) import qualified Options.Applicative as OA import Options.Applicative ((<|>)) import Path -import Stack.Runners (withBuildConfig) +import Stack.Runners (withBuildConfig, withBuildConfigDot) import Stack.Types.Config +import Stack.Dot +import Stack.Options.DotParser (listDepsOptsParser) import System.Process.PagerEditor (pageText) import System.Directory (listDirectory) import Network.HTTP.Client.TLS (getGlobalManager) @@ -45,9 +48,9 @@ data SnapshotType | Nightly deriving (Show, Eq, Ord) -newtype LsCmds = - LsSnapshot SnapshotOpts - deriving (Eq, Show, Ord) +data LsCmds + = LsSnapshot SnapshotOpts + | LsDependencies ListDepsOpts data SnapshotOpts = SnapshotOpts { soptViewType :: LsView @@ -57,13 +60,16 @@ data SnapshotOpts = SnapshotOpts newtype LsCmdOpts = LsCmdOpts { lsView :: LsCmds - } deriving (Eq, Show, Ord) + } lsParser :: OA.Parser LsCmdOpts -lsParser = LsCmdOpts <$> OA.hsubparser lsSnapCmd +lsParser = LsCmdOpts <$> OA.hsubparser (lsSnapCmd <> lsDepsCmd) lsCmdOptsParser :: OA.Parser LsCmds -lsCmdOptsParser = fmap LsSnapshot lsViewSnapCmd +lsCmdOptsParser = LsSnapshot <$> lsViewSnapCmd + +lsDepOptsParser :: OA.Parser LsCmds +lsDepOptsParser = LsDependencies <$> listDepsOptsParser lsViewSnapCmd :: OA.Parser SnapshotOpts lsViewSnapCmd = @@ -83,6 +89,12 @@ lsSnapCmd = lsCmdOptsParser (OA.progDesc "View local snapshot (default option)")) +lsDepsCmd :: OA.Mod OA.CommandFields LsCmds +lsDepsCmd = + OA.command + "dependencies" + (OA.info lsDepOptsParser (OA.progDesc "View the dependencies")) + data Snapshot = Snapshot { snapId :: Text , snapTitle :: Text @@ -190,6 +202,7 @@ handleLocal lsOpts = do displayLocalSnapshot isStdoutTerminal $ L.filter (L.isPrefixOf "night") snapData _ -> liftIO $ displayLocalSnapshot isStdoutTerminal snapData + LsDependencies _ -> return () handleRemote :: (MonadIO m, MonadThrow m, MonadReader env m, HasEnvConfig env) @@ -215,6 +228,7 @@ handleRemote lsOpts = do displaySnapshotData isStdoutTerminal $ filterSnapshotData snapData Nightly _ -> liftIO $ displaySnapshotData isStdoutTerminal snapData + LsDependencies _ -> return () where urlInfo = "https://www.stackage.org/snapshots" @@ -225,6 +239,12 @@ lsCmd lsOpts go = case soptViewType of Local -> withBuildConfig go (handleLocal lsOpts) Remote -> withBuildConfig go (handleRemote lsOpts) + LsDependencies depOpts -> listDependenciesCmd depOpts go + +-- | List the dependencies +listDependenciesCmd :: ListDepsOpts -> GlobalOpts -> IO () +listDependenciesCmd opts go = + withBuildConfigDot (listDepsDotOpts opts) go $ listDependencies opts lsViewLocalCmd :: OA.Mod OA.CommandFields LsView lsViewLocalCmd =