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
|
> 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)
|
(COMMAND | COMMAND | COMMAND)
|
||||||
|
|
||||||
Available options:
|
Available options:
|
||||||
-N,--offline only access cache
|
|
||||||
-A,--no-ansi disable ANSI codes
|
-A,--no-ansi disable ANSI codes
|
||||||
-c,--columns COLUMNS_NUMBER
|
-c,--columns COLUMNS_NUMBER
|
||||||
number of columns
|
number of columns
|
||||||
|
@ -49,12 +48,12 @@ Available commands:
|
||||||
|
|
||||||
Usual workflow:
|
Usual workflow:
|
||||||
|
|
||||||
- Print 10 last updated topics: `4r ts | head -20`
|
- Print 10 last updated topics: `4r ts -m 10`
|
||||||
|
|
||||||
Example output:
|
Example output:
|
||||||
|
|
||||||
```
|
```
|
||||||
> 4r ts | head -20
|
> 4r ts -m 10
|
||||||
Переезжаю: @abzyk at 2022-06-27 21:01:10 #31
|
Переезжаю: @abzyk at 2022-06-27 21:01:10 #31
|
||||||
|
|
||||||
Пожелания: @nick at 2022-06-27 20:43:34 #20
|
Пожелания: @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 :: Parser Options
|
||||||
optsParser =
|
optsParser =
|
||||||
Options <$> switch (long "no-ansi" <> short 'A' <> help "disable ANSI codes")
|
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)
|
<|> pure Nothing)
|
||||||
<*> choiceParser
|
<*> choiceParser
|
||||||
|
|
||||||
data Choice = GetSections
|
data Choice = GetSections
|
||||||
| GetTopics
|
| GetTopics { maxEntries :: Maybe Int }
|
||||||
| GetTopic {topic_id :: Integer}
|
| GetTopic { topic_id :: Integer }
|
||||||
deriving stock (Show)
|
deriving stock (Show)
|
||||||
|
|
||||||
choiceParser :: Parser Choice
|
choiceParser :: Parser Choice
|
||||||
|
@ -41,7 +44,10 @@ choiceParser = foldl1 (<|>)
|
||||||
(progDesc "Request list of sections")))
|
(progDesc "Request list of sections")))
|
||||||
, subparser
|
, subparser
|
||||||
(command "ts" (info
|
(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")))
|
(progDesc "Request list of topics")))
|
||||||
, subparser
|
, subparser
|
||||||
(command "t" (info
|
(command "t" (info
|
||||||
|
|
|
@ -45,11 +45,11 @@ program GetSections = do
|
||||||
sections <- Api.getSections
|
sections <- Api.getSections
|
||||||
withSgr [SetColor Foreground Vivid White] do
|
withSgr [SetColor Foreground Vivid White] do
|
||||||
sequenceA_ $ intersperse (putTextLnO "") (printColor <$> sections)
|
sequenceA_ $ intersperse (putTextLnO "") (printColor <$> sections)
|
||||||
program GetTopics = do
|
program GetTopics{maxEntries} = do
|
||||||
topics <- Api.getTopics
|
topics <- Api.getTopics
|
||||||
withSgr [SetColor Foreground Vivid White] do
|
withSgr [SetColor Foreground Vivid White] do
|
||||||
sequenceA_ $ intersperse (putTextLnO "")
|
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
|
program GetTopic{topic_id} = do
|
||||||
topic <- Api.getTopic topic_id
|
topic <- Api.getTopic topic_id
|
||||||
withSgr [SetColor Foreground Vivid White] do
|
withSgr [SetColor Foreground Vivid White] do
|
||||||
|
|
Loading…
Reference in New Issue