import qualified Data.ByteString.Lazy as Byte
import MetaJuicer.MetaJuicer
import MetaJuicer.PNG.PNG
import System (getArgs)
import Data.Maybe
import Data.Attoparsec.Lazy


-- | Runs the program, taking the file as the argument
main :: IO ()
main = do args <- getArgs   
          case args of 
                [] -> showHelp
                x -> (Byte.readFile . concat) x >>= (print . getMahJUICE)

-- | Can be called in order to display the help message
showHelp :: IO ()
showHelp = putStr $ "Usage: metajuicer <file> \nWhere file is the file you want to take the metadata from.\n" ++ 
                    "Currently supported formats are:\n" ++
                    "\t- PNG\n"

-- | Takes the file and attempts to parse it
getMahJUICE :: Byte.ByteString -> Juice
getMahJUICE bs = case parse (getPNG <?> "Unkown filetype") bs of
                        Fail _ _ s-> error $ "Error while parsing file" ++ s
                        Done bs r -> r
