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

{-|
Module      : Stack.Options.IdeParser
Description : Parse arguments for Stack's @ide@ commands.
License     : BSD-3-Clause

Functions to parse command line arguments for Stack's @ide@ commands.
-}

module Stack.Options.IdeParser
  ( idePackagesParser
  , ideTargetsParser
  ) where

import           Options.Applicative ( Parser, flag, help, long, switch )
import           Stack.Prelude
import           Stack.Types.IdeOpts ( ListPackagesCmd (..), OutputStream (..) )

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

idePackagesParser :: Parser (OutputStream, ListPackagesCmd)
idePackagesParser :: Parser (OutputStream, ListPackagesCmd)
idePackagesParser = (,) (OutputStream
 -> ListPackagesCmd -> (OutputStream, ListPackagesCmd))
-> Parser OutputStream
-> Parser (ListPackagesCmd -> (OutputStream, ListPackagesCmd))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser OutputStream
outputFlag Parser (ListPackagesCmd -> (OutputStream, ListPackagesCmd))
-> Parser ListPackagesCmd -> Parser (OutputStream, ListPackagesCmd)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser ListPackagesCmd
cabalFileFlag

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

ideTargetsParser :: Parser ((Bool, Bool, Bool), OutputStream)
ideTargetsParser :: Parser ((Bool, Bool, Bool), OutputStream)
ideTargetsParser =
  (,) ((Bool, Bool, Bool)
 -> OutputStream -> ((Bool, Bool, Bool), OutputStream))
-> Parser (Bool, Bool, Bool)
-> Parser (OutputStream -> ((Bool, Bool, Bool), OutputStream))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ((,,) (Bool -> Bool -> Bool -> (Bool, Bool, Bool))
-> Parser Bool -> Parser (Bool -> Bool -> (Bool, Bool, Bool))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser Bool
exeFlag Parser (Bool -> Bool -> (Bool, Bool, Bool))
-> Parser Bool -> Parser (Bool -> (Bool, Bool, Bool))
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser Bool
testFlag Parser (Bool -> (Bool, Bool, Bool))
-> Parser Bool -> Parser (Bool, Bool, Bool)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser Bool
benchFlag) Parser (OutputStream -> ((Bool, Bool, Bool), OutputStream))
-> Parser OutputStream -> Parser ((Bool, Bool, Bool), OutputStream)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser OutputStream
outputFlag

outputFlag :: Parser OutputStream
outputFlag :: Parser OutputStream
outputFlag = OutputStream
-> OutputStream
-> Mod FlagFields OutputStream
-> Parser OutputStream
forall a. a -> a -> Mod FlagFields a -> Parser a
flag
  OutputStream
OutputLogInfo
  OutputStream
OutputStdout
  (  String -> Mod FlagFields OutputStream
forall (f :: * -> *) a. HasName f => String -> Mod f a
long String
"stdout"
  Mod FlagFields OutputStream
-> Mod FlagFields OutputStream -> Mod FlagFields OutputStream
forall a. Semigroup a => a -> a -> a
<> String -> Mod FlagFields OutputStream
forall (f :: * -> *) a. String -> Mod f a
help String
"Send output to the standard output stream instead of the \
          \default, the standard error stream."
  )

cabalFileFlag :: Parser ListPackagesCmd
cabalFileFlag :: Parser ListPackagesCmd
cabalFileFlag = ListPackagesCmd
-> ListPackagesCmd
-> Mod FlagFields ListPackagesCmd
-> Parser ListPackagesCmd
forall a. a -> a -> Mod FlagFields a -> Parser a
flag
  ListPackagesCmd
ListPackageNames
  ListPackagesCmd
ListPackageCabalFiles
  (  String -> Mod FlagFields ListPackagesCmd
forall (f :: * -> *) a. HasName f => String -> Mod f a
long String
"cabal-files"
  Mod FlagFields ListPackagesCmd
-> Mod FlagFields ListPackagesCmd -> Mod FlagFields ListPackagesCmd
forall a. Semigroup a => a -> a -> a
<> String -> Mod FlagFields ListPackagesCmd
forall (f :: * -> *) a. String -> Mod f a
help String
"Print paths to package Cabal files instead of package \
          \names."
  )

exeFlag :: Parser Bool
exeFlag :: Parser Bool
exeFlag = Mod FlagFields Bool -> Parser Bool
switch
  (  String -> Mod FlagFields Bool
forall (f :: * -> *) a. HasName f => String -> Mod f a
long String
"exes"
  Mod FlagFields Bool -> Mod FlagFields Bool -> Mod FlagFields Bool
forall a. Semigroup a => a -> a -> a
<> String -> Mod FlagFields Bool
forall (f :: * -> *) a. String -> Mod f a
help String
"Include executables."
  )

testFlag :: Parser Bool
testFlag :: Parser Bool
testFlag = Mod FlagFields Bool -> Parser Bool
switch
  (  String -> Mod FlagFields Bool
forall (f :: * -> *) a. HasName f => String -> Mod f a
long String
"tests"
  Mod FlagFields Bool -> Mod FlagFields Bool -> Mod FlagFields Bool
forall a. Semigroup a => a -> a -> a
<> String -> Mod FlagFields Bool
forall (f :: * -> *) a. String -> Mod f a
help String
"Include test suites."
  )

benchFlag :: Parser Bool
benchFlag :: Parser Bool
benchFlag = Mod FlagFields Bool -> Parser Bool
switch
  (  String -> Mod FlagFields Bool
forall (f :: * -> *) a. HasName f => String -> Mod f a
long String
"benchmarks"
  Mod FlagFields Bool -> Mod FlagFields Bool -> Mod FlagFields Bool
forall a. Semigroup a => a -> a -> a
<> String -> Mod FlagFields Bool
forall (f :: * -> *) a. String -> Mod f a
help String
"Include benchmarks."
  )