module Git.Vogue.PluginCommon
(
hsFiles,
getPluginCommand,
pCommand,
PluginCommand(..),
) where
import Control.Applicative
import Data.List
import Options.Applicative
hsFiles :: IO [FilePath]
hsFiles = filter (isSuffixOf ".hs") . lines <$> getContents
data PluginCommand
= CmdCheck
| CmdFix
| CmdName
pluginCommandParser :: Parser PluginCommand
pluginCommandParser = subparser
( pCommand "name" CmdName "Get name of plugin"
<> pCommand "check" CmdCheck "Check for problems"
<> pCommand "fix" CmdFix "Try to fix problems"
)
pCommand :: String -> a -> String -> Mod CommandFields a
pCommand name ctor desc = command name (info (pure ctor) (progDesc desc))
getPluginCommand :: String -> String -> IO PluginCommand
getPluginCommand hdr desc = execParser parser
where
parser = info (helper <*> pluginCommandParser)
( fullDesc
<> progDesc desc
<> header hdr)