Skip to content

Commit 6ca7464

Browse files
head-gardenerBodigrim
authored andcommitted
feat(CLI): use --count when --info is passed
1 parent e8774e2 commit 6ca7464

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/Action/CmdLine.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ search_ = Search
134134
,jsonl = def &= name "jsonl" &= help "Get result as JSONL (JSON Lines)"
135135
,link = def &= help "Give URL's for each result"
136136
,numbers = def &= help "Give counter for each result"
137-
,info = def &= help "Give extended information about the first result"
137+
,info = def &= help "Give extended information about the first n results (set n with --count, default is 1)"
138138
,database = def &= typFile &= help "Name of database to use (use .hoo extension)"
139139
,count = Nothing &= name "n" &= help "Maximum number of results to return (defaults to 10)"
140140
,query = def &= args &= typ "QUERY"

src/Action/Search.hs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,10 @@ actionSearch Search{..} = replicateM_ repeat_ $ -- deliberately reopen the datab
5656
if null res then
5757
putStrLn "No results found"
5858
else if info then do
59-
putStr $ targetInfo color' q $ headErr res
59+
mapM_ (putStr . targetInfo color' q)
60+
$ (case count of
61+
Just c -> take c
62+
Nothing -> singleton . headErr) res
6063
else do
6164
if | json -> LBS.putStrLn $ JSON.encode $ maybe id take count $ map unHTMLtargetItem res
6265
| jsonl -> mapM_ (LBS.putStrLn . JSON.encode) $ maybe id take count $ map unHTMLtargetItem res

0 commit comments

Comments
 (0)