slackbuilder/app/SlackBuilder/CommandLine.hs

104 lines
3.3 KiB
Haskell
Raw Normal View History

module SlackBuilder.CommandLine
2023-08-09 20:59:42 +02:00
( GhArguments(..)
, SlackBuilderCommand(..)
, PackagistArguments(..)
, TextArguments(..)
, slackBuilderParser
) where
import Data.Text (Text)
import Options.Applicative
( Parser
, ParserInfo(..)
, metavar
, argument
, str
, info
, fullDesc
, subparser
2023-08-10 12:47:43 +02:00
, command, optional
)
data SlackBuilderCommand
= PackagistCommand PackagistArguments
| TextCommand TextArguments
2023-08-09 20:59:42 +02:00
| GhCommand GhArguments
2023-08-15 10:33:19 +02:00
| SlackBuildCommand Text Text
| CommitCommand Text Text
| ExistsCommand Text
| ArchiveCommand Text Text String Text
2023-08-21 13:38:20 +02:00
| DownloadCommand Text String
2023-08-25 10:30:24 +02:00
| CloneCommand Text Text Text
2023-08-28 21:05:47 +02:00
| DownloadAndDeployCommand Text Text
2023-09-03 10:26:43 +02:00
| Up2DateCommand
2023-08-15 10:33:19 +02:00
deriving (Eq, Show)
data PackagistArguments = PackagistArguments
{ vendor :: Text
, name :: Text
} deriving (Eq, Show)
2023-08-09 20:59:42 +02:00
data GhArguments = GhArguments
{ owner :: Text
, name :: Text
2023-08-10 12:47:43 +02:00
, transform :: Maybe Text
2023-08-09 20:59:42 +02:00
} deriving (Eq, Show)
newtype TextArguments = TextArguments Text
2023-08-15 10:33:19 +02:00
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")
2023-08-09 20:59:42 +02:00
ghArguments :: Parser GhArguments
ghArguments = GhArguments
<$> argument str (metavar "OWNER")
<*> argument str (metavar "NAME")
2023-08-10 12:47:43 +02:00
<*> optional (argument str (metavar "TRANSFORM"))
2023-08-09 20:59:42 +02:00
slackBuilderParser :: ParserInfo SlackBuilderCommand
slackBuilderParser = info slackBuilderCommand fullDesc
slackBuilderCommand :: Parser SlackBuilderCommand
slackBuilderCommand = subparser
$ command "packagist" (info (PackagistCommand <$> packagistArguments) mempty)
<> command "text" (info (TextCommand <$> textArguments) mempty)
2023-08-09 20:59:42 +02:00
<> command "github" (info (GhCommand <$> ghArguments) mempty)
2023-08-15 10:33:19 +02:00
<> command "slackbuild" (info slackBuildCommand mempty)
<> command "commit" (info commitCommand mempty)
<> command "exists" (info existsCommand mempty)
<> command "archive" (info archiveCommand mempty)
2023-08-21 13:38:20 +02:00
<> command "download" (info downloadCommand mempty)
2023-08-25 10:30:24 +02:00
<> command "clone" (info cloneCommand mempty)
2023-08-28 21:05:47 +02:00
<> command "deploy" (info deployCommand mempty)
2023-09-03 10:26:43 +02:00
<> command "up2date" (info up2DateCommand mempty)
2023-08-15 10:33:19 +02:00
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")
2023-08-21 13:38:20 +02:00
downloadCommand = DownloadCommand
<$> argument str (metavar "URI")
<*> argument str (metavar "TARGET")
2023-08-25 10:30:24 +02:00
cloneCommand = CloneCommand
<$> argument str (metavar "REPO")
<*> argument str (metavar "TARBALL")
<*> argument str (metavar "TAG_PREFIX")
2023-08-28 21:05:47 +02:00
deployCommand = DownloadAndDeployCommand
<$> argument str (metavar "URI")
<*> argument str (metavar "TARBALL")
2023-09-03 10:26:43 +02:00
up2DateCommand = pure Up2DateCommand