slackbuilder/app/SlackBuilder/CommandLine.hs
2023-09-03 10:26:43 +02:00

104 lines
3.3 KiB
Haskell

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
| DownloadCommand Text String
| CloneCommand Text Text Text
| DownloadAndDeployCommand Text Text
| Up2DateCommand
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)
<> 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