{-# LANGUAGE NoImplicitPrelude #-}

-- | Functions to parse command line arguments for Stack's @sdist@ and @upload@

-- commands.

module Stack.Options.SDistParser
 ( sdistOptsParser
 ) where

import           Options.Applicative
                   ( Parser, completer, help, idm, long, metavar, strArgument
                   , strOption, switch
                   )
import           Options.Applicative.Builder.Extra ( boolFlags, dirCompleter )
import           Stack.Prelude
import           Stack.SDist ( SDistOpts (..) )
import           Stack.Options.HpcReportParser ( pvpBoundsOption )

-- | Parse command line arguments for Stack's @sdist@ and @upload@ commands.

sdistOptsParser :: Parser SDistOpts
sdistOptsParser :: Parser SDistOpts
sdistOptsParser = [String]
-> Maybe PvpBounds -> Bool -> Bool -> Maybe String -> SDistOpts
SDistOpts
  ([String]
 -> Maybe PvpBounds -> Bool -> Bool -> Maybe String -> SDistOpts)
-> Parser [String]
-> Parser
     (Maybe PvpBounds -> Bool -> Bool -> Maybe String -> SDistOpts)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser String -> Parser [String]
forall a. Parser a -> Parser [a]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many (Mod ArgumentFields String -> Parser String
forall s. IsString s => Mod ArgumentFields s -> Parser s
strArgument
        (  String -> Mod ArgumentFields String
forall (f :: * -> *) a. HasMetavar f => String -> Mod f a
metavar String
"DIR"
        Mod ArgumentFields String
-> Mod ArgumentFields String -> Mod ArgumentFields String
forall a. Semigroup a => a -> a -> a
<> Completer -> Mod ArgumentFields String
forall (f :: * -> *) a. HasCompleter f => Completer -> Mod f a
completer Completer
dirCompleter
        ))
  Parser
  (Maybe PvpBounds -> Bool -> Bool -> Maybe String -> SDistOpts)
-> Parser (Maybe PvpBounds)
-> Parser (Bool -> Bool -> Maybe String -> SDistOpts)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser PvpBounds -> Parser (Maybe PvpBounds)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional Parser PvpBounds
pvpBoundsOption
  Parser (Bool -> Bool -> Maybe String -> SDistOpts)
-> Parser Bool -> Parser (Bool -> Maybe String -> SDistOpts)
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
ignoreCheckSwitch
  Parser (Bool -> Maybe String -> SDistOpts)
-> Parser Bool -> Parser (Maybe String -> SDistOpts)
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
buildPackageOption
  Parser (Maybe String -> SDistOpts)
-> Parser (Maybe String) -> Parser SDistOpts
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser String -> Parser (Maybe String)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional (Mod OptionFields String -> Parser String
forall s. IsString s => Mod OptionFields s -> Parser s
strOption
        (  String -> Mod OptionFields String
forall (f :: * -> *) a. HasName f => String -> Mod f a
long String
"tar-dir"
        Mod OptionFields String
-> Mod OptionFields String -> Mod OptionFields String
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields String
forall (f :: * -> *) a. String -> Mod f a
help String
"If specified, copy all the tar to this directory."
        ))
 where
  ignoreCheckSwitch :: Parser Bool
ignoreCheckSwitch = Mod FlagFields Bool -> Parser Bool
switch
    (  String -> Mod FlagFields Bool
forall (f :: * -> *) a. HasName f => String -> Mod f a
long String
"ignore-check"
    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
"Do not check package for common mistakes."
    )
  buildPackageOption :: Parser Bool
buildPackageOption = Bool -> String -> String -> Mod FlagFields Bool -> Parser Bool
boolFlags Bool
False
    String
"test-tarball"
    String
"building of the resulting tarball."
    Mod FlagFields Bool
forall m. Monoid m => m
idm