{-# LANGUAGE CPP #-}
module HaskellCI.Cli where
import HaskellCI.Prelude
import System.Exit (exitFailure)
import System.FilePath.Posix (takeFileName)
import System.IO (hPutStrLn, stderr)
import qualified Options.Applicative as O
import HaskellCI.Config
import HaskellCI.OptparseGrammar
import HaskellCI.VersionInfo
data Command
= CommandTravis FilePath
| CommandBash FilePath
| CommandGitHub FilePath
| CommandRegenerate
| CommandListGHC
| CommandDumpConfig
| CommandVersionInfo
deriving Int -> Command -> ShowS
[Command] -> ShowS
Command -> String
(Int -> Command -> ShowS)
-> (Command -> String) -> ([Command] -> ShowS) -> Show Command
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Command] -> ShowS
$cshowList :: [Command] -> ShowS
show :: Command -> String
$cshow :: Command -> String
showsPrec :: Int -> Command -> ShowS
$cshowsPrec :: Int -> Command -> ShowS
Show
data Options = Options
{ Options -> Maybe Output
optOutput :: Maybe Output
, Options -> ConfigOpt
optConfig :: ConfigOpt
, Options -> Maybe String
optCwd :: Maybe FilePath
, Options -> Maybe InputType
optInputType :: Maybe InputType
, Options -> Config -> Config
optConfigMorphism :: Config -> Config
}
instance Semigroup Options where
Options Maybe Output
b ConfigOpt
d Maybe String
c Maybe InputType
e Config -> Config
f <> :: Options -> Options -> Options
<> Options Maybe Output
b' ConfigOpt
d' Maybe String
c' Maybe InputType
e' Config -> Config
f' =
Maybe Output
-> ConfigOpt
-> Maybe String
-> Maybe InputType
-> (Config -> Config)
-> Options
Options (Maybe Output
b Maybe Output -> Maybe Output -> Maybe Output
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Maybe Output
b') (ConfigOpt
d ConfigOpt -> ConfigOpt -> ConfigOpt
forall a. Semigroup a => a -> a -> a
<> ConfigOpt
d') (Maybe String
c Maybe String -> Maybe String -> Maybe String
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Maybe String
c') (Maybe InputType
e Maybe InputType -> Maybe InputType -> Maybe InputType
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Maybe InputType
e') (Config -> Config
f' (Config -> Config) -> (Config -> Config) -> Config -> Config
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Config -> Config
f)
defaultOptions :: Options
defaultOptions :: Options
defaultOptions = Options :: Maybe Output
-> ConfigOpt
-> Maybe String
-> Maybe InputType
-> (Config -> Config)
-> Options
Options
{ optOutput :: Maybe Output
optOutput = Maybe Output
forall a. Maybe a
Nothing
, optConfig :: ConfigOpt
optConfig = ConfigOpt
ConfigOptAuto
, optCwd :: Maybe String
optCwd = Maybe String
forall a. Maybe a
Nothing
, optInputType :: Maybe InputType
optInputType = Maybe InputType
forall a. Maybe a
Nothing
, optConfigMorphism :: Config -> Config
optConfigMorphism = Config -> Config
forall a. a -> a
id
}
optionsWithOutputFile :: FilePath -> Options
optionsWithOutputFile :: String -> Options
optionsWithOutputFile String
fp = Options
defaultOptions
{ optOutput :: Maybe Output
optOutput = Output -> Maybe Output
forall a. a -> Maybe a
Just (String -> Output
OutputFile String
fp)
}
data Output = OutputStdout | OutputFile FilePath
data ConfigOpt
= ConfigOptAuto
| ConfigOpt FilePath
| ConfigOptNo
deriving (ConfigOpt -> ConfigOpt -> Bool
(ConfigOpt -> ConfigOpt -> Bool)
-> (ConfigOpt -> ConfigOpt -> Bool) -> Eq ConfigOpt
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ConfigOpt -> ConfigOpt -> Bool
$c/= :: ConfigOpt -> ConfigOpt -> Bool
== :: ConfigOpt -> ConfigOpt -> Bool
$c== :: ConfigOpt -> ConfigOpt -> Bool
Eq, Int -> ConfigOpt -> ShowS
[ConfigOpt] -> ShowS
ConfigOpt -> String
(Int -> ConfigOpt -> ShowS)
-> (ConfigOpt -> String)
-> ([ConfigOpt] -> ShowS)
-> Show ConfigOpt
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ConfigOpt] -> ShowS
$cshowList :: [ConfigOpt] -> ShowS
show :: ConfigOpt -> String
$cshow :: ConfigOpt -> String
showsPrec :: Int -> ConfigOpt -> ShowS
$cshowsPrec :: Int -> ConfigOpt -> ShowS
Show)
instance Semigroup ConfigOpt where
ConfigOpt
a <> :: ConfigOpt -> ConfigOpt -> ConfigOpt
<> ConfigOpt
ConfigOptAuto = ConfigOpt
a
ConfigOpt
_ <> ConfigOpt
b = ConfigOpt
b
data InputType
= InputTypePackage
| InputTypeProject
deriving Int -> InputType -> ShowS
[InputType] -> ShowS
InputType -> String
(Int -> InputType -> ShowS)
-> (InputType -> String)
-> ([InputType] -> ShowS)
-> Show InputType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [InputType] -> ShowS
$cshowList :: [InputType] -> ShowS
show :: InputType -> String
$cshow :: InputType -> String
showsPrec :: Int -> InputType -> ShowS
$cshowsPrec :: Int -> InputType -> ShowS
Show
optInputType' :: Options -> FilePath -> InputType
optInputType' :: Options -> String -> InputType
optInputType' Options
opts String
path =
InputType -> Maybe InputType -> InputType
forall a. a -> Maybe a -> a
fromMaybe InputType
def (Options -> Maybe InputType
optInputType Options
opts)
where
def :: InputType
def | String
"cabal.project" String -> String -> Bool
forall a. Eq a => [a] -> [a] -> Bool
`isPrefixOf` ShowS
takeFileName String
path = InputType
InputTypeProject
| Bool
otherwise = InputType
InputTypePackage
optionsP :: O.Parser Options
optionsP :: Parser Options
optionsP = Maybe Output
-> ConfigOpt
-> Maybe String
-> Maybe InputType
-> (Config -> Config)
-> Options
Options
(Maybe Output
-> ConfigOpt
-> Maybe String
-> Maybe InputType
-> (Config -> Config)
-> Options)
-> Parser (Maybe Output)
-> Parser
(ConfigOpt
-> Maybe String
-> Maybe InputType
-> (Config -> Config)
-> Options)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser Output -> Parser (Maybe Output)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
O.optional Parser Output
outputP
Parser
(ConfigOpt
-> Maybe String
-> Maybe InputType
-> (Config -> Config)
-> Options)
-> Parser ConfigOpt
-> Parser
(Maybe String -> Maybe InputType -> (Config -> Config) -> Options)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser ConfigOpt
configOptP
Parser
(Maybe String -> Maybe InputType -> (Config -> Config) -> Options)
-> Parser (Maybe String)
-> Parser (Maybe InputType -> (Config -> Config) -> Options)
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)
O.optional (Mod OptionFields String -> Parser String
forall s. IsString s => Mod OptionFields s -> Parser s
O.strOption (String -> Mod OptionFields String
forall (f :: * -> *) a. HasName f => String -> Mod f a
O.long String
"cwd" Mod OptionFields String
-> Mod OptionFields String -> Mod OptionFields String
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields String
forall (f :: * -> *) a. HasMetavar f => String -> Mod f a
O.metavar String
"Dir" Mod OptionFields String
-> Mod OptionFields String -> Mod OptionFields String
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields String
forall (f :: * -> *) a. HasCompleter f => String -> Mod f a
O.action String
"directory" 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
O.help String
"Directory to change to"))
Parser (Maybe InputType -> (Config -> Config) -> Options)
-> Parser (Maybe InputType)
-> Parser ((Config -> Config) -> Options)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser InputType -> Parser (Maybe InputType)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
O.optional Parser InputType
inputTypeP
Parser ((Config -> Config) -> Options)
-> Parser (Config -> Config) -> Parser Options
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> OptparseGrammar Config Config -> Parser (Config -> Config)
forall s a. OptparseGrammar s a -> Parser (s -> s)
runOptparseGrammar OptparseGrammar Config Config
forall (c :: * -> Constraint) (g :: * -> * -> *).
(OptionsGrammar c g, Applicative (g Config), c (Identity HLintJob),
c (Identity PackageScope), c (Identity TestedWithJobs),
c (Identity Ubuntu), c (Identity Jobs), c (Identity CopyFields),
c (Identity Version), c (Identity Natural), c Env, c Folds,
c CopyFields, c HeadVersion,
c (List FSep (Identity Installed) Installed),
Applicative (g DoctestConfig), Applicative (g DocspecConfig),
Applicative (g HLintConfig)) =>
g Config Config
configGrammar
configOptP :: O.Parser ConfigOpt
configOptP :: Parser ConfigOpt
configOptP = Parser ConfigOpt
file Parser ConfigOpt -> Parser ConfigOpt -> Parser ConfigOpt
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parser ConfigOpt
noconfig Parser ConfigOpt -> Parser ConfigOpt -> Parser ConfigOpt
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> ConfigOpt -> Parser ConfigOpt
forall (f :: * -> *) a. Applicative f => a -> f a
pure ConfigOpt
ConfigOptAuto
where
file :: Parser ConfigOpt
file = String -> ConfigOpt
ConfigOpt (String -> ConfigOpt) -> Parser String -> Parser ConfigOpt
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Mod OptionFields String -> Parser String
forall s. IsString s => Mod OptionFields s -> Parser s
O.strOption (String -> Mod OptionFields String
forall (f :: * -> *) a. HasName f => String -> Mod f a
O.long String
"config" Mod OptionFields String
-> Mod OptionFields String -> Mod OptionFields String
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields String
forall (f :: * -> *) a. HasMetavar f => String -> Mod f a
O.metavar String
"CONFIGFILE" Mod OptionFields String
-> Mod OptionFields String -> Mod OptionFields String
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields String
forall (f :: * -> *) a. HasCompleter f => String -> Mod f a
O.action String
"file" 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
O.help String
"Configuration file")
noconfig :: Parser ConfigOpt
noconfig = ConfigOpt -> Mod FlagFields ConfigOpt -> Parser ConfigOpt
forall a. a -> Mod FlagFields a -> Parser a
O.flag' ConfigOpt
ConfigOptNo (String -> Mod FlagFields ConfigOpt
forall (f :: * -> *) a. HasName f => String -> Mod f a
O.long String
"no-config" Mod FlagFields ConfigOpt
-> Mod FlagFields ConfigOpt -> Mod FlagFields ConfigOpt
forall a. Semigroup a => a -> a -> a
<> String -> Mod FlagFields ConfigOpt
forall (f :: * -> *) a. String -> Mod f a
O.help String
"Don't read configuration file")
outputP :: O.Parser Output
outputP :: Parser Output
outputP =
String -> Output
OutputFile (String -> Output) -> Parser String -> Parser Output
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Mod OptionFields String -> Parser String
forall s. IsString s => Mod OptionFields s -> Parser s
O.strOption (String -> Mod OptionFields String
forall (f :: * -> *) a. HasName f => String -> Mod f a
O.long String
"output" Mod OptionFields String
-> Mod OptionFields String -> Mod OptionFields String
forall a. Semigroup a => a -> a -> a
<> Char -> Mod OptionFields String
forall (f :: * -> *) a. HasName f => Char -> Mod f a
O.short Char
'o' Mod OptionFields String
-> Mod OptionFields String -> Mod OptionFields String
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields String
forall (f :: * -> *) a. HasMetavar f => String -> Mod f a
O.metavar String
"FILE" Mod OptionFields String
-> Mod OptionFields String -> Mod OptionFields String
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields String
forall (f :: * -> *) a. HasCompleter f => String -> Mod f a
O.action String
"file" 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
O.help String
"Output file") Parser Output -> Parser Output -> Parser Output
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>
Output -> Mod FlagFields Output -> Parser Output
forall a. a -> Mod FlagFields a -> Parser a
O.flag' Output
OutputStdout (String -> Mod FlagFields Output
forall (f :: * -> *) a. HasName f => String -> Mod f a
O.long String
"stdout" Mod FlagFields Output
-> Mod FlagFields Output -> Mod FlagFields Output
forall a. Semigroup a => a -> a -> a
<> String -> Mod FlagFields Output
forall (f :: * -> *) a. String -> Mod f a
O.help String
"Use stdout output")
versionP :: O.Parser (a -> a)
versionP :: Parser (a -> a)
versionP = String -> Mod OptionFields (a -> a) -> Parser (a -> a)
forall a. String -> Mod OptionFields (a -> a) -> Parser (a -> a)
O.infoOption String
haskellCIVerStr (Mod OptionFields (a -> a) -> Parser (a -> a))
-> Mod OptionFields (a -> a) -> Parser (a -> a)
forall a b. (a -> b) -> a -> b
$ [Mod OptionFields (a -> a)] -> Mod OptionFields (a -> a)
forall a. Monoid a => [a] -> a
mconcat
[ String -> Mod OptionFields (a -> a)
forall (f :: * -> *) a. HasName f => String -> Mod f a
O.long String
"version"
, Char -> Mod OptionFields (a -> a)
forall (f :: * -> *) a. HasName f => Char -> Mod f a
O.short Char
'V'
, String -> Mod OptionFields (a -> a)
forall (f :: * -> *) a. String -> Mod f a
O.help String
"Print version information"
]
inputTypeP :: O.Parser InputType
inputTypeP :: Parser InputType
inputTypeP = Parser InputType
pkg Parser InputType -> Parser InputType -> Parser InputType
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parser InputType
prj where
pkg :: Parser InputType
pkg = InputType -> Mod FlagFields InputType -> Parser InputType
forall a. a -> Mod FlagFields a -> Parser a
O.flag' InputType
InputTypePackage (Mod FlagFields InputType -> Parser InputType)
-> Mod FlagFields InputType -> Parser InputType
forall a b. (a -> b) -> a -> b
$ String -> Mod FlagFields InputType
forall (f :: * -> *) a. HasName f => String -> Mod f a
O.long String
"package"
prj :: Parser InputType
prj = InputType -> Mod FlagFields InputType -> Parser InputType
forall a. a -> Mod FlagFields a -> Parser a
O.flag' InputType
InputTypeProject (Mod FlagFields InputType -> Parser InputType)
-> Mod FlagFields InputType -> Parser InputType
forall a b. (a -> b) -> a -> b
$ String -> Mod FlagFields InputType
forall (f :: * -> *) a. HasName f => String -> Mod f a
O.long String
"project"
cliParserInfo :: O.ParserInfo (Command, Options)
cliParserInfo :: ParserInfo (Command, Options)
cliParserInfo = Parser (Command, Options)
-> InfoMod (Command, Options) -> ParserInfo (Command, Options)
forall a. Parser a -> InfoMod a -> ParserInfo a
O.info ((,) (Command -> Options -> (Command, Options))
-> Parser Command -> Parser (Options -> (Command, Options))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser Command
cmdP Parser (Options -> (Command, Options))
-> Parser Options -> Parser (Command, Options)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser Options
optionsP Parser (Command, Options)
-> Parser ((Command, Options) -> (Command, Options))
-> Parser (Command, Options)
forall (f :: * -> *) a b. Applicative f => f a -> f (a -> b) -> f b
O.<**> Parser ((Command, Options) -> (Command, Options))
forall a. Parser (a -> a)
versionP Parser (Command, Options)
-> Parser ((Command, Options) -> (Command, Options))
-> Parser (Command, Options)
forall (f :: * -> *) a b. Applicative f => f a -> f (a -> b) -> f b
O.<**> Parser ((Command, Options) -> (Command, Options))
forall a. Parser (a -> a)
O.helper) (InfoMod (Command, Options) -> ParserInfo (Command, Options))
-> InfoMod (Command, Options) -> ParserInfo (Command, Options)
forall a b. (a -> b) -> a -> b
$ [InfoMod (Command, Options)] -> InfoMod (Command, Options)
forall a. Monoid a => [a] -> a
mconcat
[ InfoMod (Command, Options)
forall a. InfoMod a
O.fullDesc
, String -> InfoMod (Command, Options)
forall a. String -> InfoMod a
O.header String
"haskell-ci - generate CI scripts for Haskell projects"
]
where
cmdP :: Parser Command
cmdP = Mod CommandFields Command -> Parser Command
forall a. Mod CommandFields a -> Parser a
O.subparser ([Mod CommandFields Command] -> Mod CommandFields Command
forall a. Monoid a => [a] -> a
mconcat
[ String -> ParserInfo Command -> Mod CommandFields Command
forall a. String -> ParserInfo a -> Mod CommandFields a
O.command String
"regenerate" (ParserInfo Command -> Mod CommandFields Command)
-> ParserInfo Command -> Mod CommandFields Command
forall a b. (a -> b) -> a -> b
$ Parser Command -> InfoMod Command -> ParserInfo Command
forall a. Parser a -> InfoMod a -> ParserInfo a
O.info (Command -> Parser Command
forall (f :: * -> *) a. Applicative f => a -> f a
pure Command
CommandRegenerate) (InfoMod Command -> ParserInfo Command)
-> InfoMod Command -> ParserInfo Command
forall a b. (a -> b) -> a -> b
$ String -> InfoMod Command
forall a. String -> InfoMod a
O.progDesc String
"Regenerate outputs"
, String -> ParserInfo Command -> Mod CommandFields Command
forall a. String -> ParserInfo a -> Mod CommandFields a
O.command String
"travis" (ParserInfo Command -> Mod CommandFields Command)
-> ParserInfo Command -> Mod CommandFields Command
forall a b. (a -> b) -> a -> b
$ Parser Command -> InfoMod Command -> ParserInfo Command
forall a. Parser a -> InfoMod a -> ParserInfo a
O.info Parser Command
travisP (InfoMod Command -> ParserInfo Command)
-> InfoMod Command -> ParserInfo Command
forall a b. (a -> b) -> a -> b
$ String -> InfoMod Command
forall a. String -> InfoMod a
O.progDesc String
"Generate travis-ci config"
, String -> ParserInfo Command -> Mod CommandFields Command
forall a. String -> ParserInfo a -> Mod CommandFields a
O.command String
"bash" (ParserInfo Command -> Mod CommandFields Command)
-> ParserInfo Command -> Mod CommandFields Command
forall a b. (a -> b) -> a -> b
$ Parser Command -> InfoMod Command -> ParserInfo Command
forall a. Parser a -> InfoMod a -> ParserInfo a
O.info Parser Command
bashP (InfoMod Command -> ParserInfo Command)
-> InfoMod Command -> ParserInfo Command
forall a b. (a -> b) -> a -> b
$ String -> InfoMod Command
forall a. String -> InfoMod a
O.progDesc String
"Generate local-bash-docker script"
, String -> ParserInfo Command -> Mod CommandFields Command
forall a. String -> ParserInfo a -> Mod CommandFields a
O.command String
"github" (ParserInfo Command -> Mod CommandFields Command)
-> ParserInfo Command -> Mod CommandFields Command
forall a b. (a -> b) -> a -> b
$ Parser Command -> InfoMod Command -> ParserInfo Command
forall a. Parser a -> InfoMod a -> ParserInfo a
O.info Parser Command
githubP (InfoMod Command -> ParserInfo Command)
-> InfoMod Command -> ParserInfo Command
forall a b. (a -> b) -> a -> b
$ String -> InfoMod Command
forall a. String -> InfoMod a
O.progDesc String
"Generate GitHub Actions config"
, String -> ParserInfo Command -> Mod CommandFields Command
forall a. String -> ParserInfo a -> Mod CommandFields a
O.command String
"list-ghc" (ParserInfo Command -> Mod CommandFields Command)
-> ParserInfo Command -> Mod CommandFields Command
forall a b. (a -> b) -> a -> b
$ Parser Command -> InfoMod Command -> ParserInfo Command
forall a. Parser a -> InfoMod a -> ParserInfo a
O.info (Command -> Parser Command
forall (f :: * -> *) a. Applicative f => a -> f a
pure Command
CommandListGHC) (InfoMod Command -> ParserInfo Command)
-> InfoMod Command -> ParserInfo Command
forall a b. (a -> b) -> a -> b
$ String -> InfoMod Command
forall a. String -> InfoMod a
O.progDesc String
"List known GHC versions"
, String -> ParserInfo Command -> Mod CommandFields Command
forall a. String -> ParserInfo a -> Mod CommandFields a
O.command String
"dump-config" (ParserInfo Command -> Mod CommandFields Command)
-> ParserInfo Command -> Mod CommandFields Command
forall a b. (a -> b) -> a -> b
$ Parser Command -> InfoMod Command -> ParserInfo Command
forall a. Parser a -> InfoMod a -> ParserInfo a
O.info (Command -> Parser Command
forall (f :: * -> *) a. Applicative f => a -> f a
pure Command
CommandDumpConfig) (InfoMod Command -> ParserInfo Command)
-> InfoMod Command -> ParserInfo Command
forall a b. (a -> b) -> a -> b
$ String -> InfoMod Command
forall a. String -> InfoMod a
O.progDesc String
"Dump cabal.haskell-ci config with default values"
, String -> ParserInfo Command -> Mod CommandFields Command
forall a. String -> ParserInfo a -> Mod CommandFields a
O.command String
"version-info" (ParserInfo Command -> Mod CommandFields Command)
-> ParserInfo Command -> Mod CommandFields Command
forall a b. (a -> b) -> a -> b
$ Parser Command -> InfoMod Command -> ParserInfo Command
forall a. Parser a -> InfoMod a -> ParserInfo a
O.info (Command -> Parser Command
forall (f :: * -> *) a. Applicative f => a -> f a
pure Command
CommandVersionInfo) (InfoMod Command -> ParserInfo Command)
-> InfoMod Command -> ParserInfo Command
forall a b. (a -> b) -> a -> b
$ String -> InfoMod Command
forall a. String -> InfoMod a
O.progDesc String
"Print versions info haskell-ci was compiled with"
]) Parser Command -> Parser Command -> Parser Command
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parser Command
travisP
travisP :: Parser Command
travisP = String -> Command
CommandTravis
(String -> Command) -> Parser String -> Parser Command
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Mod ArgumentFields String -> Parser String
forall s. IsString s => Mod ArgumentFields s -> Parser s
O.strArgument (String -> Mod ArgumentFields String
forall (f :: * -> *) a. HasMetavar f => String -> Mod f a
O.metavar String
"CABAL.FILE" Mod ArgumentFields String
-> Mod ArgumentFields String -> Mod ArgumentFields String
forall a. Semigroup a => a -> a -> a
<> String -> Mod ArgumentFields String
forall (f :: * -> *) a. HasCompleter f => String -> Mod f a
O.action String
"file" Mod ArgumentFields String
-> Mod ArgumentFields String -> Mod ArgumentFields String
forall a. Semigroup a => a -> a -> a
<> String -> Mod ArgumentFields String
forall (f :: * -> *) a. String -> Mod f a
O.help String
"Either <pkg.cabal> or cabal.project")
bashP :: Parser Command
bashP = String -> Command
CommandBash
(String -> Command) -> Parser String -> Parser Command
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Mod ArgumentFields String -> Parser String
forall s. IsString s => Mod ArgumentFields s -> Parser s
O.strArgument (String -> Mod ArgumentFields String
forall (f :: * -> *) a. HasMetavar f => String -> Mod f a
O.metavar String
"CABAL.FILE" Mod ArgumentFields String
-> Mod ArgumentFields String -> Mod ArgumentFields String
forall a. Semigroup a => a -> a -> a
<> String -> Mod ArgumentFields String
forall (f :: * -> *) a. HasCompleter f => String -> Mod f a
O.action String
"file" Mod ArgumentFields String
-> Mod ArgumentFields String -> Mod ArgumentFields String
forall a. Semigroup a => a -> a -> a
<> String -> Mod ArgumentFields String
forall (f :: * -> *) a. String -> Mod f a
O.help String
"Either <pkg.cabal> or cabal.project")
githubP :: Parser Command
githubP = String -> Command
CommandGitHub
(String -> Command) -> Parser String -> Parser Command
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Mod ArgumentFields String -> Parser String
forall s. IsString s => Mod ArgumentFields s -> Parser s
O.strArgument (String -> Mod ArgumentFields String
forall (f :: * -> *) a. HasMetavar f => String -> Mod f a
O.metavar String
"CABAL.FILE" Mod ArgumentFields String
-> Mod ArgumentFields String -> Mod ArgumentFields String
forall a. Semigroup a => a -> a -> a
<> String -> Mod ArgumentFields String
forall (f :: * -> *) a. HasCompleter f => String -> Mod f a
O.action String
"file" Mod ArgumentFields String
-> Mod ArgumentFields String -> Mod ArgumentFields String
forall a. Semigroup a => a -> a -> a
<> String -> Mod ArgumentFields String
forall (f :: * -> *) a. String -> Mod f a
O.help String
"Either <pkg.cabal> or cabal.project")
parseOptions :: [String] -> IO (FilePath, Options)
parseOptions :: [String] -> IO (String, Options)
parseOptions [String]
argv = case ParserResult (Command, Options)
res of
O.Success (Command
cmd, Options
opts) -> do
String
path <- Command -> IO String
fromCmd Command
cmd
(String, Options) -> IO (String, Options)
forall (m :: * -> *) a. Monad m => a -> m a
return (String
path, Options
opts)
O.Failure ParserFailure ParserHelp
f -> case ParserFailure ParserHelp -> String -> (String, ExitCode)
O.renderFailure ParserFailure ParserHelp
f String
"haskell-ci" of
(String
help, ExitCode
_) -> Handle -> String -> IO ()
hPutStrLn Handle
stderr String
help IO () -> IO (String, Options) -> IO (String, Options)
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> IO (String, Options)
forall a. IO a
exitFailure
O.CompletionInvoked CompletionResult
_ -> IO (String, Options)
forall a. IO a
exitFailure
where
res :: ParserResult (Command, Options)
res = ParserPrefs
-> ParserInfo (Command, Options)
-> [String]
-> ParserResult (Command, Options)
forall a. ParserPrefs -> ParserInfo a -> [String] -> ParserResult a
O.execParserPure (PrefsMod -> ParserPrefs
O.prefs PrefsMod
O.subparserInline) ParserInfo (Command, Options)
cliParserInfo [String]
argv
fromCmd :: Command -> IO FilePath
fromCmd :: Command -> IO String
fromCmd (CommandTravis String
fp) = String -> IO String
forall (m :: * -> *) a. Monad m => a -> m a
return String
fp
fromCmd (CommandBash String
fp) = String -> IO String
forall (m :: * -> *) a. Monad m => a -> m a
return String
fp
fromCmd (CommandGitHub String
fp) = String -> IO String
forall (m :: * -> *) a. Monad m => a -> m a
return String
fp
fromCmd Command
cmd = String -> IO String
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> IO String) -> String -> IO String
forall a b. (a -> b) -> a -> b
$ String
"Command without filepath: " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Command -> String
forall a. Show a => a -> String
show Command
cmd