{-# LANGUAGE NoImplicitPrelude #-}

module Stack.Options.CleanParser
  ( cleanOptsParser
  ) where

import           Options.Applicative ( Parser, flag', help, long, metavar )
import           Stack.Clean ( CleanCommand (..), CleanOpts (..) )
import           Stack.Prelude
import           Stack.Types.PackageName ( packageNameArgument )

-- | Command-line parser for the clean command.

cleanOptsParser :: CleanCommand -> Parser CleanOpts
cleanOptsParser :: CleanCommand -> Parser CleanOpts
cleanOptsParser CleanCommand
Clean = [PackageName] -> CleanOpts
CleanShallow
  ([PackageName] -> CleanOpts)
-> Parser [PackageName] -> Parser CleanOpts
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser [PackageName]
packages
  Parser CleanOpts -> Parser CleanOpts -> Parser CleanOpts
forall a. Parser a -> Parser a -> Parser a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parser CleanOpts
doFullClean
 where
  packages :: Parser [PackageName]
packages = Parser PackageName -> Parser [PackageName]
forall a. Parser a -> Parser [a]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many (Mod ArgumentFields PackageName -> Parser PackageName
packageNameArgument
    (  String -> Mod ArgumentFields PackageName
forall (f :: * -> *) a. HasMetavar f => String -> Mod f a
metavar String
"PACKAGE"
    Mod ArgumentFields PackageName
-> Mod ArgumentFields PackageName -> Mod ArgumentFields PackageName
forall a. Semigroup a => a -> a -> a
<> String -> Mod ArgumentFields PackageName
forall (f :: * -> *) a. String -> Mod f a
help String
"If none specified, clean all project packages."
    ))
  doFullClean :: Parser CleanOpts
doFullClean = CleanOpts -> Mod FlagFields CleanOpts -> Parser CleanOpts
forall a. a -> Mod FlagFields a -> Parser a
flag' CleanOpts
CleanFull
    (  String -> Mod FlagFields CleanOpts
forall (f :: * -> *) a. HasName f => String -> Mod f a
long String
"full"
    Mod FlagFields CleanOpts
-> Mod FlagFields CleanOpts -> Mod FlagFields CleanOpts
forall a. Semigroup a => a -> a -> a
<> String -> Mod FlagFields CleanOpts
forall (f :: * -> *) a. String -> Mod f a
help String
"Delete the project's Stack working directories (.stack-work by \
            \default)."
    )

cleanOptsParser CleanCommand
Purge = CleanOpts -> Parser CleanOpts
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure CleanOpts
CleanFull