summaryrefslogtreecommitdiff
path: root/app/SlackBuilder/CommandLine.hs
blob: 53a6bfb92f945800f2006d64cb20eb1e0ee08b4b (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
85
86
87
88
89
90
91
module SlackBuilder.CommandLine
    ( GhArguments(..)
    , SlackBuilderCommand(..)
    , PackagistArguments(..)
    , TextArguments(..)
    , slackBuilderParser
    ) where

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

data SlackBuilderCommand
    = TextCommand TextArguments
    | SlackBuildCommand Text Text
    | CommitCommand Text Text
    | ExistsCommand Text
    | ArchiveCommand Text Text String Text
    | DownloadCommand Text String
    | CloneCommand Text Text Text
    | DownloadAndDeployCommand Text Text
    | Up2DateCommand

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

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

data TextArguments = TextArguments
    { versionPicker :: Text -> Text
    , textURL :: Text
    }

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

slackBuilderParser :: ParserInfo SlackBuilderCommand
slackBuilderParser = info slackBuilderCommand fullDesc

slackBuilderCommand :: Parser SlackBuilderCommand
slackBuilderCommand = subparser
    $ command "text" (info (TextCommand <$> textArguments) mempty)
    <> command "slackbuild" (info slackBuildCommand mempty)
    <> command "commit" (info commitCommand mempty)
    <> command "exists" (info existsCommand mempty)
    <> command "archive" (info archiveCommand mempty)
    <> command "download" (info downloadCommand mempty)
    <> command "clone" (info cloneCommand mempty)
    <> command "deploy" (info deployCommand mempty)
    <> command "up2date" (info up2DateCommand 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")
    downloadCommand = DownloadCommand
        <$> argument str (metavar "URI")
        <*> argument str (metavar "TARGET")
    cloneCommand = CloneCommand
        <$> argument str (metavar "REPO")
        <*> argument str (metavar "TARBALL")
        <*> argument str (metavar "TAG_PREFIX")
    deployCommand = DownloadAndDeployCommand
        <$> argument str (metavar "URI")
        <*> argument str (metavar "TARBALL")
    up2DateCommand = pure Up2DateCommand