@@ -16,6 +16,13 @@ import Options.Applicative
1616 showHelpOnError ,
1717 strOption ,
1818 )
19+ import Practiscore.USPSA.CLI (streamRawReport )
20+ import Practiscore.Parser.Shooter (toUspsaMemberId )
21+ import Conduit qualified
22+ import Conduit ((.|) , MonadThrow , MonadUnliftIO )
23+ import Practiscore.Parser.Report qualified
24+ import Control.Exception (throwIO )
25+ import Practiscore.USPSA.Match (getShooterMatch , encodeMatch )
1926
2027data CLI = CLI
2128 { uspsaMemberId :: Text ,
@@ -50,10 +57,19 @@ data CliParseErrors
5057
5158instance Exception CliParseErrors
5259
53- parseCLI :: IO ()
60+ parseCLI :: ( MonadUnliftIO m , MonadThrow m ) => m ()
5461parseCLI = do
55- _cli <- showHelpOnErrorOnExecParser (info (helper <*> cli) fullDesc)
56- pure ()
62+ cli <- liftIO $ showHelpOnErrorOnExecParser (info (helper <*> cli) fullDesc)
63+
64+ Conduit. runConduitRes $ do
65+ let stream = streamRawReport cli. reportPath
66+ shooters <- lift $ Practiscore.Parser.Report. toShooters stream
67+ scores <- lift $ Practiscore.Parser.Report. toScores stream
68+ case toUspsaMemberId cli. uspsaMemberId of
69+ Nothing -> liftIO $ throwIO (InvalidUspsaMemberId $ cli. uspsaMemberId <> " is not valid" )
70+ Just uspsaMemberId ->
71+ Conduit. yield (toStrict $ encodeMatch $ getShooterMatch uspsaMemberId shooters scores)
72+ .| Conduit. sinkFile cli. output
5773
5874showHelpOnErrorOnExecParser :: ParserInfo a -> IO a
5975showHelpOnErrorOnExecParser = customExecParser (prefs showHelpOnError)
0 commit comments