module Vimeta.UI.CommandLine (run) where
import Data.Monoid
import Data.Version (showVersion)
import Options.Applicative
import System.Exit
import qualified Vimeta.UI.CommandLine.Config as Config
import qualified Vimeta.UI.CommandLine.Movie as Movie
import qualified Vimeta.UI.CommandLine.TV as TV
import Paths_vimeta (version)
import Prelude
data Command = CmdVersion
| CmdConfig Config.Options
| CmdMovie Movie.Options
| CmdTV TV.Options
optionsParser :: Parser Command
optionsParser = verbose <|> commands
where
verbose =
flag' CmdVersion
(long "version" <> help "Print version and exit")
commands =
subparser $ mconcat [config, movie, tv]
config =
command "config"
(info (CmdConfig <$> Config.optionsParser) (progDesc configDesc))
movie =
command "movie"
(info (CmdMovie <$> Movie.optionsParser) (progDesc movieDesc))
tv =
command "tv"
(info (CmdTV <$> TV.optionsParser) (progDesc tvDesc))
configDesc =
"Create a new configuration file"
movieDesc =
"Tag a movie file using data from TheMovieDB.org"
tvDesc =
"Tag episode files using data from TheMovieDB.org"
run :: IO ()
run = do
options <- execParser $ info (optionsParser <**> helper) idm
case options of
CmdVersion -> putStrLn (showVersion version)
CmdConfig o -> Config.run o
CmdMovie o -> Movie.run o
CmdTV o -> TV.run o
exitSuccess