{-# LANGUAGE NoImplicitPrelude   #-}
{-# LANGUAGE OverloadedStrings   #-}

-- | Functions to parse command line arguments for Stack's @ls@ command.

module Stack.Options.LsParser
  ( lsOptsParser
  ) where

import qualified Options.Applicative as OA
import           Options.Applicative ( idm )
import           Options.Applicative.Builder.Extra ( boolFlags )
import           Stack.Constants ( globalFooter )
import           Stack.Ls
                   ( ListStylesOpts (..), ListToolsOpts (..), LsCmdOpts (..)
                   , LsCmds (..), LsView (..), SnapshotOpts (..)
                   )
import           Stack.Options.DotParser ( listDepsOptsParser )
import           Stack.Prelude

-- | Parse command line arguments for Stack's @ls@ command.

lsOptsParser :: OA.Parser LsCmdOpts
lsOptsParser :: Parser LsCmdOpts
lsOptsParser = LsCmds -> LsCmdOpts
LsCmdOpts
  forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Mod CommandFields a -> Parser a
OA.hsubparser (Mod CommandFields LsCmds
lsSnapCmd forall a. Semigroup a => a -> a -> a
<> Mod CommandFields LsCmds
lsDepsCmd forall a. Semigroup a => a -> a -> a
<> Mod CommandFields LsCmds
lsStylesCmd forall a. Semigroup a => a -> a -> a
<> Mod CommandFields LsCmds
lsToolsCmd)

lsCmdOptsParser :: OA.Parser LsCmds
lsCmdOptsParser :: Parser LsCmds
lsCmdOptsParser = SnapshotOpts -> LsCmds
LsSnapshot forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser SnapshotOpts
lsViewSnapCmd

lsDepOptsParser :: OA.Parser LsCmds
lsDepOptsParser :: Parser LsCmds
lsDepOptsParser = ListDepsOpts -> LsCmds
LsDependencies forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser ListDepsOpts
listDepsOptsParser

lsStylesOptsParser :: OA.Parser LsCmds
lsStylesOptsParser :: Parser LsCmds
lsStylesOptsParser = ListStylesOpts -> LsCmds
LsStyles forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser ListStylesOpts
listStylesOptsParser

lsToolsOptsParser :: OA.Parser LsCmds
lsToolsOptsParser :: Parser LsCmds
lsToolsOptsParser = ListToolsOpts -> LsCmds
LsTools forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser ListToolsOpts
listToolsOptsParser

listStylesOptsParser :: OA.Parser ListStylesOpts
listStylesOptsParser :: Parser ListStylesOpts
listStylesOptsParser = Bool -> Bool -> Bool -> ListStylesOpts
ListStylesOpts
  forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Bool -> String -> String -> Mod FlagFields Bool -> Parser Bool
boolFlags Bool
False
        String
"basic"
        String
"a basic report of the styles used. The default is a fuller one."
        forall m. Monoid m => m
idm
  forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Bool -> String -> String -> Mod FlagFields Bool -> Parser Bool
boolFlags Bool
True
        String
"sgr"
        String
"the provision of the equivalent SGR instructions (provided by \
        \default). Flag ignored for a basic report."
        forall m. Monoid m => m
idm
  forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Bool -> String -> String -> Mod FlagFields Bool -> Parser Bool
boolFlags Bool
True
        String
"example"
        String
"the provision of an example of the applied style (provided by default \
        \for colored output). Flag ignored for a basic report."
        forall m. Monoid m => m
idm

listToolsOptsParser :: OA.Parser ListToolsOpts
listToolsOptsParser :: Parser ListToolsOpts
listToolsOptsParser = String -> ListToolsOpts
ListToolsOpts
  forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s. IsString s => Mod OptionFields s -> Parser s
OA.strOption
        (  forall (f :: * -> *) a. HasName f => String -> Mod f a
OA.long String
"filter"
        forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. HasMetavar f => String -> Mod f a
OA.metavar String
"TOOL_NAME"
        forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. HasValue f => a -> Mod f a
OA.value String
""
        forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. String -> Mod f a
OA.help String
"Filter by a tool name (eg 'ghc', 'ghc-git' or 'msys2') \
                   \- case sensitive. (default: no filter)"
        )

lsViewSnapCmd :: OA.Parser SnapshotOpts
lsViewSnapCmd :: Parser SnapshotOpts
lsViewSnapCmd = LsView -> Bool -> Bool -> SnapshotOpts
SnapshotOpts
  forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ( forall a. Mod CommandFields a -> Parser a
OA.hsubparser (Mod CommandFields LsView
lsViewRemoteCmd forall a. Semigroup a => a -> a -> a
<> Mod CommandFields LsView
lsViewLocalCmd) forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> forall (f :: * -> *) a. Applicative f => a -> f a
pure LsView
Local)
  forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Mod FlagFields Bool -> Parser Bool
OA.switch
        (  forall (f :: * -> *) a. HasName f => String -> Mod f a
OA.long String
"lts"
        forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. HasName f => Char -> Mod f a
OA.short Char
'l'
        forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. String -> Mod f a
OA.help String
"Only show LTS Haskell snapshots."
        )
  forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Mod FlagFields Bool -> Parser Bool
OA.switch
        (  forall (f :: * -> *) a. HasName f => String -> Mod f a
OA.long String
"nightly"
        forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. HasName f => Char -> Mod f a
OA.short Char
'n'
        forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. String -> Mod f a
OA.help String
"Only show Nightly snapshots."
        )

lsSnapCmd :: OA.Mod OA.CommandFields LsCmds
lsSnapCmd :: Mod CommandFields LsCmds
lsSnapCmd = forall a. String -> ParserInfo a -> Mod CommandFields a
OA.command String
"snapshots" forall a b. (a -> b) -> a -> b
$
  forall a. Parser a -> InfoMod a -> ParserInfo a
OA.info Parser LsCmds
lsCmdOptsParser forall a b. (a -> b) -> a -> b
$
       forall a. String -> InfoMod a
OA.progDesc String
"View snapshots. (default: local)"
    forall a. Semigroup a => a -> a -> a
<> forall a. String -> InfoMod a
OA.footer String
localSnapshotMsg

lsDepsCmd :: OA.Mod OA.CommandFields LsCmds
lsDepsCmd :: Mod CommandFields LsCmds
lsDepsCmd = forall a. String -> ParserInfo a -> Mod CommandFields a
OA.command String
"dependencies" forall a b. (a -> b) -> a -> b
$
  forall a. Parser a -> InfoMod a -> ParserInfo a
OA.info Parser LsCmds
lsDepOptsParser forall a b. (a -> b) -> a -> b
$
       forall a. String -> InfoMod a
OA.progDesc String
"View the dependencies."
    forall a. Semigroup a => a -> a -> a
<> forall a. String -> InfoMod a
OA.footer String
globalFooter

lsStylesCmd :: OA.Mod OA.CommandFields LsCmds
lsStylesCmd :: Mod CommandFields LsCmds
lsStylesCmd =
     forall a. String -> ParserInfo a -> Mod CommandFields a
OA.command
       String
"stack-colors"
       (forall a. Parser a -> InfoMod a -> ParserInfo a
OA.info Parser LsCmds
lsStylesOptsParser
                (forall a. String -> InfoMod a
OA.progDesc String
"View Stack's output styles."))
  forall a. Semigroup a => a -> a -> a
<> forall a. String -> ParserInfo a -> Mod CommandFields a
OA.command
       String
"stack-colours"
       (forall a. Parser a -> InfoMod a -> ParserInfo a
OA.info Parser LsCmds
lsStylesOptsParser
                (forall a. String -> InfoMod a
OA.progDesc String
"View Stack's output styles (alias for \
                             \'stack-colors')."))

lsToolsCmd :: OA.Mod OA.CommandFields LsCmds
lsToolsCmd :: Mod CommandFields LsCmds
lsToolsCmd =
  forall a. String -> ParserInfo a -> Mod CommandFields a
OA.command
    String
"tools"
    (forall a. Parser a -> InfoMod a -> ParserInfo a
OA.info Parser LsCmds
lsToolsOptsParser
             (forall a. String -> InfoMod a
OA.progDesc String
"View Stack's installed tools."))

lsViewLocalCmd :: OA.Mod OA.CommandFields LsView
lsViewLocalCmd :: Mod CommandFields LsView
lsViewLocalCmd = forall a. String -> ParserInfo a -> Mod CommandFields a
OA.command String
"local" forall a b. (a -> b) -> a -> b
$
  forall a. Parser a -> InfoMod a -> ParserInfo a
OA.info (forall (f :: * -> *) a. Applicative f => a -> f a
pure LsView
Local) forall a b. (a -> b) -> a -> b
$
       forall a. String -> InfoMod a
OA.progDesc String
"View local snapshots."
    forall a. Semigroup a => a -> a -> a
<> forall a. String -> InfoMod a
OA.footer String
localSnapshotMsg

lsViewRemoteCmd :: OA.Mod OA.CommandFields LsView
lsViewRemoteCmd :: Mod CommandFields LsView
lsViewRemoteCmd = forall a. String -> ParserInfo a -> Mod CommandFields a
OA.command String
"remote" forall a b. (a -> b) -> a -> b
$
  forall a. Parser a -> InfoMod a -> ParserInfo a
OA.info (forall (f :: * -> *) a. Applicative f => a -> f a
pure LsView
Remote) forall a b. (a -> b) -> a -> b
$
       forall a. String -> InfoMod a
OA.progDesc String
"View remote snapshots."
    forall a. Semigroup a => a -> a -> a
<> forall a. String -> InfoMod a
OA.footer String
pagerMsg

pagerMsg :: String
pagerMsg :: String
pagerMsg =
  String
"On a terminal, uses a pager, if one is available. Respects the PAGER \
  \environment variable (subject to that, prefers pager 'less' to 'more')."

localSnapshotMsg :: String
localSnapshotMsg :: String
localSnapshotMsg =
  String
"A local snapshot is identified by a hash code. " forall a. Semigroup a => a -> a -> a
<> String
pagerMsg