Commit 8f47d29c authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[main] add optparse for command line parsing

parent 63e6bb6c
......@@ -6,6 +6,7 @@ module Main where
import NeatInterpolation (text)
import Network.HTTP.Client (newManager)
import Network.HTTP.Client.TLS (tlsManagerSettings)
import Options.Applicative
import Servant.Client
import HAL (getMetadataWith)
......@@ -16,14 +17,34 @@ import Tree
import qualified Data.Text as T
data CountParams = CountParams
{ cp_query :: T.Text }
data Command = Count CountParams
countParams :: Parser Command
countParams = Count <$>
(CountParams
<$> strArgument (metavar "query"))
params :: Parser Command
params = subparser
(command "count" (info countParams (progDesc "Count number of docs for a given query")))
opts :: ParserInfo Command
opts = info (params <**> helper)
(fullDesc
<> progDesc "A program to test HAL"
<> header "crawlerHAL-exe")
yearReq = [text|
(language_t:en)
AND (producedDateY_i:2015
OR producedDateY_i:2016
OR producedDateY_i:2017
OR producedDateY_i:2018
(language_t:en)
AND (producedDateY_i:2015
OR producedDateY_i:2016
OR producedDateY_i:2017
OR producedDateY_i:2018
OR producedDateY_i:2021
OR producedDateY_i:2022)
OR producedDateY_i:2022)
AND (structId_i:302102
OR structId_i:469216
OR structId_i:6279
......@@ -63,8 +84,15 @@ imt = [
]
main :: IO ()
main = do
res <- getMetadataWith (generateRequestByStructID "artificial intelligence" imt) (Just 0) (Just 55)
main = run =<< execParser opts
-- res <- getMetadataWith (generateRequestByStructID "artificial intelligence" imt) (Just 0) (Just 55)
-- case res of
-- (Left err) -> print err
-- (Right val) -> print $ _docs val
run :: Command -> IO ()
run (Count (CountParams { cp_query })) = do
res <- getMetadataWithC (cp_query) (Just 0) Nothing
case res of
(Left err) -> print err
(Right val) -> print $ _docs val
Left err -> print err
Right (cnt, _docsC) -> print $ show cnt
cabal-version: 1.12
-- This file has been generated from package.yaml by hpack version 0.34.4.
-- This file has been generated from package.yaml by hpack version 0.35.0.
--
-- see: https://github.com/sol/hpack
--
-- hash: 5e660f75d650f1d72f17df082838eb0dc3d6bdd2f514b9931a97ddc17a47b5c0
-- hash: d5f6b9788433a3873efd55684dfd55f4d85380f24209a6a8eb8ba80c82a330f8
name: crawlerHAL
version: 0.1.0.0
......@@ -54,6 +54,7 @@ library
, http-client-tls
, lens
, neat-interpolation
, optparse-applicative
, scientific
, servant
, servant-client
......@@ -89,6 +90,7 @@ executable crawlerHAL-exe
, http-client-tls
, lens
, neat-interpolation
, optparse-applicative
, scientific
, servant
, servant-client
......@@ -125,6 +127,7 @@ test-suite halCrawler-test
, http-client-tls
, lens
, neat-interpolation
, optparse-applicative
, scientific
, servant
, servant-client
......
......@@ -30,6 +30,7 @@ dependencies:
- http-client-tls
- lens
- neat-interpolation
- optparse-applicative
- scientific
- servant
- servant-client
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment