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 ...@@ -6,6 +6,7 @@ module Main where
import NeatInterpolation (text) import NeatInterpolation (text)
import Network.HTTP.Client (newManager) import Network.HTTP.Client (newManager)
import Network.HTTP.Client.TLS (tlsManagerSettings) import Network.HTTP.Client.TLS (tlsManagerSettings)
import Options.Applicative
import Servant.Client import Servant.Client
import HAL (getMetadataWith) import HAL (getMetadataWith)
...@@ -16,14 +17,34 @@ import Tree ...@@ -16,14 +17,34 @@ import Tree
import qualified Data.Text as T 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| yearReq = [text|
(language_t:en) (language_t:en)
AND (producedDateY_i:2015 AND (producedDateY_i:2015
OR producedDateY_i:2016 OR producedDateY_i:2016
OR producedDateY_i:2017 OR producedDateY_i:2017
OR producedDateY_i:2018 OR producedDateY_i:2018
OR producedDateY_i:2021 OR producedDateY_i:2021
OR producedDateY_i:2022) OR producedDateY_i:2022)
AND (structId_i:302102 AND (structId_i:302102
OR structId_i:469216 OR structId_i:469216
OR structId_i:6279 OR structId_i:6279
...@@ -63,8 +84,15 @@ imt = [ ...@@ -63,8 +84,15 @@ imt = [
] ]
main :: IO () main :: IO ()
main = do main = run =<< execParser opts
res <- getMetadataWith (generateRequestByStructID "artificial intelligence" imt) (Just 0) (Just 55) -- 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 case res of
(Left err) -> print err Left err -> print err
(Right val) -> print $ _docs val Right (cnt, _docsC) -> print $ show cnt
cabal-version: 1.12 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 -- see: https://github.com/sol/hpack
-- --
-- hash: 5e660f75d650f1d72f17df082838eb0dc3d6bdd2f514b9931a97ddc17a47b5c0 -- hash: d5f6b9788433a3873efd55684dfd55f4d85380f24209a6a8eb8ba80c82a330f8
name: crawlerHAL name: crawlerHAL
version: 0.1.0.0 version: 0.1.0.0
...@@ -54,6 +54,7 @@ library ...@@ -54,6 +54,7 @@ library
, http-client-tls , http-client-tls
, lens , lens
, neat-interpolation , neat-interpolation
, optparse-applicative
, scientific , scientific
, servant , servant
, servant-client , servant-client
...@@ -89,6 +90,7 @@ executable crawlerHAL-exe ...@@ -89,6 +90,7 @@ executable crawlerHAL-exe
, http-client-tls , http-client-tls
, lens , lens
, neat-interpolation , neat-interpolation
, optparse-applicative
, scientific , scientific
, servant , servant
, servant-client , servant-client
...@@ -125,6 +127,7 @@ test-suite halCrawler-test ...@@ -125,6 +127,7 @@ test-suite halCrawler-test
, http-client-tls , http-client-tls
, lens , lens
, neat-interpolation , neat-interpolation
, optparse-applicative
, scientific , scientific
, servant , servant
, servant-client , servant-client
......
...@@ -30,6 +30,7 @@ dependencies: ...@@ -30,6 +30,7 @@ dependencies:
- http-client-tls - http-client-tls
- lens - lens
- neat-interpolation - neat-interpolation
- optparse-applicative
- scientific - scientific
- servant - servant
- servant-client - 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