{-# LANGUAGE NoImplicitPrelude #-}

-- | Functions to parse command line arguments for Stack's @init@ and @new@

-- commands.

module Stack.Options.InitParser
  ( initOptsParser
  ) where

import           Options.Applicative
                   ( Parser, completer, help, long, metavar, switch )
import           Options.Applicative.Builder.Extra
                   ( dirCompleter, textArgument )
import           Stack.Init ( InitOpts (..) )
import           Stack.Prelude

-- | Parse command line arguments for Stack's @init@ and @new@ commands.

initOptsParser :: Parser InitOpts
initOptsParser :: Parser InitOpts
initOptsParser = [Text] -> Bool -> Bool -> Bool -> InitOpts
InitOpts
  ([Text] -> Bool -> Bool -> Bool -> InitOpts)
-> Parser [Text] -> Parser (Bool -> Bool -> Bool -> InitOpts)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser [Text]
searchDirs
  Parser (Bool -> Bool -> Bool -> InitOpts)
-> Parser Bool -> Parser (Bool -> Bool -> InitOpts)
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
omitPackages
  Parser (Bool -> Bool -> InitOpts)
-> Parser Bool -> Parser (Bool -> InitOpts)
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
overwrite
  Parser (Bool -> InitOpts) -> Parser Bool -> Parser InitOpts
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Bool -> Bool) -> Parser Bool -> Parser Bool
forall a b. (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Bool -> Bool
not Parser Bool
ignoreSubDirs
 where
  searchDirs :: Parser [Text]
searchDirs = Parser Text -> Parser [Text]
forall a. Parser a -> Parser [a]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many (Mod ArgumentFields Text -> Parser Text
textArgument
    (  String -> Mod ArgumentFields Text
forall (f :: * -> *) a. HasMetavar f => String -> Mod f a
metavar String
"DIR(S)"
    Mod ArgumentFields Text
-> Mod ArgumentFields Text -> Mod ArgumentFields Text
forall a. Semigroup a => a -> a -> a
<> Completer -> Mod ArgumentFields Text
forall (f :: * -> *) a. HasCompleter f => Completer -> Mod f a
completer Completer
dirCompleter
    Mod ArgumentFields Text
-> Mod ArgumentFields Text -> Mod ArgumentFields Text
forall a. Semigroup a => a -> a -> a
<> String -> Mod ArgumentFields Text
forall (f :: * -> *) a. String -> Mod f a
help String
"Directory, or directories, to include in the search for Cabal \
            \files, when initialising. The default is the current directory."
    ))
  ignoreSubDirs :: Parser Bool
ignoreSubDirs = Mod FlagFields Bool -> Parser Bool
switch
    (  String -> Mod FlagFields Bool
forall (f :: * -> *) a. HasName f => String -> Mod f a
long String
"ignore-subdirs"
    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 search for Cabal files in subdirectories, when \
            \initialising."
    )
  overwrite :: Parser Bool
overwrite = Mod FlagFields Bool -> Parser Bool
switch
    (  String -> Mod FlagFields Bool
forall (f :: * -> *) a. HasName f => String -> Mod f a
long String
"force"
    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
"Force an initialisation that overwrites any existing stack.yaml \
            \file."
    )
  omitPackages :: Parser Bool
omitPackages = Mod FlagFields Bool -> Parser Bool
switch
    (  String -> Mod FlagFields Bool
forall (f :: * -> *) a. HasName f => String -> Mod f a
long String
"omit-packages"
    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
"Exclude conflicting or incompatible user packages, when \
            \initialising."
    )