{-# LANGUAGE NoImplicitPrelude #-}

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

module Stack.Options.PathParser
  ( pathParser
  ) where

import qualified Data.Text as T
import           Options.Applicative ( Parser, flag, help, long )
import           Stack.Path ( paths )
import           Stack.Prelude

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

pathParser :: Parser [Text]
pathParser :: Parser [Text]
pathParser = ((String, Text, UseHaddocks (PathInfo -> Text))
 -> Parser (Maybe Text))
-> [(String, Text, UseHaddocks (PathInfo -> Text))]
-> Parser [Text]
forall (f :: * -> *) a b.
Applicative f =>
(a -> f (Maybe b)) -> [a] -> f [b]
mapMaybeA
  ( \(String
desc, Text
name, UseHaddocks (PathInfo -> Text)
_) -> Maybe Text
-> Maybe Text -> Mod FlagFields (Maybe Text) -> Parser (Maybe Text)
forall a. a -> a -> Mod FlagFields a -> Parser a
flag Maybe Text
forall a. Maybe a
Nothing (Text -> Maybe Text
forall a. a -> Maybe a
Just Text
name)
      (  String -> Mod FlagFields (Maybe Text)
forall (f :: * -> *) a. HasName f => String -> Mod f a
long (Text -> String
T.unpack Text
name)
      Mod FlagFields (Maybe Text)
-> Mod FlagFields (Maybe Text) -> Mod FlagFields (Maybe Text)
forall a. Semigroup a => a -> a -> a
<> String -> Mod FlagFields (Maybe Text)
forall (f :: * -> *) a. String -> Mod f a
help String
desc
      )
  )
  [(String, Text, UseHaddocks (PathInfo -> Text))]
paths