aboutsummaryrefslogtreecommitdiff
path: root/tea-cleaner/TeaCleaner/CommandLine.hs
blob: b74263d3454b44f3abe8bed0b9c2aa2067f3e7d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
module TeaCleaner.CommandLine
    ( ProgramOptions(..)
    , commandLineInfo
    , execParser
    ) where

import Data.Text (Text)
import Options.Applicative
    ( Parser
    , ParserInfo
    , (<**>)
    , argument
    , execParser
    , fullDesc
    , help
    , helper
    , info
    , long
    , metavar
    , progDesc
    , str
    , switch
    )

data ProgramOptions = ProgramOptions
    { server :: Text
    , token :: Text
    , liveRun :: Bool
    } deriving (Eq, Show)

commandLineInfo :: ParserInfo ProgramOptions
commandLineInfo = info (commandLine <**> helper)
    $ fullDesc <> progDesc "Helps to detect some spam gitea accounts"

commandLine :: Parser ProgramOptions
commandLine = ProgramOptions
    <$> serverOption
    <*> tokenOption
    <*> liveRunOption
  where
    serverOption = argument str
        $ metavar "SERVER" <> help "Gitea server URL"
    tokenOption = argument str
        $ metavar "TOKEN" <> help "Access token"
    liveRunOption = switch $ long "live-run" <> help "Purge suspicious users"