summaryrefslogtreecommitdiff
path: root/app/SlackBuilder/CommandLine.hs
blob: 8df1b97fc96820e0b3e18e0bafa21118bf23bbed (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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
module SlackBuilder.CommandLine
    ( GhArguments(..)
    , SlackBuilderCommand(..)
    , PackagistArguments(..)
    , TextArguments(..)
    , slackBuilderParser
    ) where

import Data.Text (Text)
import Options.Applicative
    ( Parser
    , ParserInfo(..)
    , metavar
    , argument
    , str
    , info
    , fullDesc
    , subparser
    , command, optional
    )

data SlackBuilderCommand
    = PackagistCommand PackagistArguments
    | TextCommand TextArguments
    | GhCommand GhArguments
    | SlackBuildCommand Text Text
    | CommitCommand Text Text
    | ExistsCommand Text
    | ArchiveCommand Text Text String Text
    deriving (Eq, Show)

data PackagistArguments = PackagistArguments
    { vendor :: Text
    , name :: Text
    } deriving (Eq, Show)

data GhArguments = GhArguments
    { owner :: Text
    , name :: Text
    , transform :: Maybe Text
    } deriving (Eq, Show)

newtype TextArguments = TextArguments Text
    deriving (Eq, Show)

packagistArguments :: Parser PackagistArguments
packagistArguments = PackagistArguments
    <$> argument str (metavar "VENDOR")
    <*> argument str (metavar"NAME")

textArguments :: Parser TextArguments
textArguments = TextArguments <$> argument str (metavar "URL")

ghArguments :: Parser GhArguments
ghArguments = GhArguments
    <$> argument str (metavar "OWNER")
    <*> argument str (metavar "NAME")
    <*> optional (argument str (metavar "TRANSFORM"))

slackBuilderParser :: ParserInfo SlackBuilderCommand
slackBuilderParser = info slackBuilderCommand fullDesc

slackBuilderCommand :: Parser SlackBuilderCommand
slackBuilderCommand = subparser
    $ command "packagist" (info (PackagistCommand <$> packagistArguments) mempty)
    <> command "text" (info (TextCommand <$> textArguments) mempty)
    <> command "github" (info (GhCommand <$> ghArguments) mempty)
    <> command "slackbuild" (info slackBuildCommand mempty)
    <> command "commit" (info commitCommand mempty)
    <> command "exists" (info existsCommand mempty)
    <> command "archive" (info archiveCommand mempty)
  where
    slackBuildCommand = SlackBuildCommand
        <$> argument str (metavar "PATH")
        <*> argument str (metavar "VERSION")
    commitCommand = CommitCommand
        <$> argument str (metavar "PATH")
        <*> argument str (metavar "VERSION")
    existsCommand = ExistsCommand <$> argument str (metavar "PATH")
    archiveCommand = ArchiveCommand
        <$> argument str (metavar "REPO")
        <*> argument str (metavar "NAME_VERSION")
        <*> argument str (metavar "TARBALL")
        <*> argument str (metavar "TAG_PREFIX")