Add `--max-entries` option to `ts` subcommand
parent
72d6a08043
commit
8d7a8d3e56
|
@ -31,11 +31,10 @@ After building (that took ~40min on 8-core machine) you'll have a shell with `4r
|
|||
|
||||
```
|
||||
> 4r --help
|
||||
Usage: 4r [-N|--offline] [-A|--no-ansi] [-c|--columns COLUMNS_NUMBER]
|
||||
Usage: 4r [-A|--no-ansi] [-c|--columns COLUMNS_NUMBER]
|
||||
(COMMAND | COMMAND | COMMAND)
|
||||
|
||||
Available options:
|
||||
-N,--offline only access cache
|
||||
-A,--no-ansi disable ANSI codes
|
||||
-c,--columns COLUMNS_NUMBER
|
||||
number of columns
|
||||
|
@ -49,12 +48,12 @@ Available commands:
|
|||
|
||||
Usual workflow:
|
||||
|
||||
- Print 10 last updated topics: `4r ts | head -20`
|
||||
- Print 10 last updated topics: `4r ts -m 10`
|
||||
|
||||
Example output:
|
||||
|
||||
```
|
||||
> 4r ts | head -20
|
||||
> 4r ts -m 10
|
||||
Переезжаю: @abzyk at 2022-06-27 21:01:10 #31
|
||||
|
||||
Пожелания: @nick at 2022-06-27 20:43:34 #20
|
||||
|
|
14
app/Cli.hs
14
app/Cli.hs
|
@ -24,13 +24,16 @@ data Options = Options
|
|||
optsParser :: Parser Options
|
||||
optsParser =
|
||||
Options <$> switch (long "no-ansi" <> short 'A' <> help "disable ANSI codes")
|
||||
<*> (Just <$> option auto (metavar "COLUMNS_NUMBER" <> long "columns" <> short 'c' <> help "number of columns")
|
||||
<*> (Just <$> option auto (metavar "COLUMNS_NUMBER"
|
||||
<> long "columns"
|
||||
<> short 'c'
|
||||
<> help "number of columns")
|
||||
<|> pure Nothing)
|
||||
<*> choiceParser
|
||||
|
||||
data Choice = GetSections
|
||||
| GetTopics
|
||||
| GetTopic {topic_id :: Integer}
|
||||
| GetTopics { maxEntries :: Maybe Int }
|
||||
| GetTopic { topic_id :: Integer }
|
||||
deriving stock (Show)
|
||||
|
||||
choiceParser :: Parser Choice
|
||||
|
@ -41,7 +44,10 @@ choiceParser = foldl1 (<|>)
|
|||
(progDesc "Request list of sections")))
|
||||
, subparser
|
||||
(command "ts" (info
|
||||
(pure GetTopics)
|
||||
(GetTopics <$> (Just <$> option auto (metavar "MAX_ENTRIES_NUMBER"
|
||||
<> long "max-entries"
|
||||
<> short 'm'
|
||||
<> help "max number of entries")))
|
||||
(progDesc "Request list of topics")))
|
||||
, subparser
|
||||
(command "t" (info
|
||||
|
|
|
@ -45,11 +45,11 @@ program GetSections = do
|
|||
sections <- Api.getSections
|
||||
withSgr [SetColor Foreground Vivid White] do
|
||||
sequenceA_ $ intersperse (putTextLnO "") (printColor <$> sections)
|
||||
program GetTopics = do
|
||||
program GetTopics{maxEntries} = do
|
||||
topics <- Api.getTopics
|
||||
withSgr [SetColor Foreground Vivid White] do
|
||||
sequenceA_ $ intersperse (putTextLnO "")
|
||||
(fmap printColor . reverse $ sortBy (comparing (.last_activity_date)) topics)
|
||||
(fmap printColor . maybe id take maxEntries . reverse $ sortBy (comparing (.last_activity_date)) topics)
|
||||
program GetTopic{topic_id} = do
|
||||
topic <- Api.getTopic topic_id
|
||||
withSgr [SetColor Foreground Vivid White] do
|
||||
|
|
Loading…
Reference in New Issue