Skip to content

Commit

Permalink
Port list-dependencies under new ls sub command
Browse files Browse the repository at this point in the history
  • Loading branch information
psibi committed Dec 25, 2017
1 parent 8266a06 commit 9dc6113
Showing 1 changed file with 27 additions and 7 deletions.
34 changes: 27 additions & 7 deletions src/Stack/Ls.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
module Stack.Ls
( lsCmd
, lsParser
, listDependenciesCmd
) where

import Control.Exception (Exception, throw)
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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 =
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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"

Expand All @@ -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 =
Expand Down

0 comments on commit 9dc6113

Please sign in to comment.